testing 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. * Testing
  2. Daily <a href="http://www.go-mono.com/tests/index.php">test</a> results.
  3. Testing is an important part of the Mono project: every one of its
  4. three major components has a test suite tailored for its needs. This
  5. is very helpful, because in the course of developing the software it
  6. is very common to introduce bugs in existing code. A test suite
  7. helps us fix the bugs as soon as they are introduced.
  8. There are various kinds of tests in Mono:
  9. <ul>
  10. <li><a href="#unit"><b>Class Library Unit
  11. Tests:</b></a> These are used to test the class
  12. libraries.
  13. <li><a href="#compiler"><b>Compiler tests</b></a>: Both
  14. tests that should pass and tests that should fail are included.
  15. <li><a href="#runtime"><b>Runtime tests</b></a>: Tests for
  16. the virtual machine.
  17. <li><a href="#aspnet"><b>ASP.NET tests</b></a>: ASP.NET tests.
  18. <li><a href="#ws"><b>Web Services tests</b></a>: Web Services
  19. client/server tests.
  20. </ul>
  21. <a name="unit"></a>
  22. * Class Library Tests
  23. All classes in Mono libraries should have comprehensive unit test
  24. suites to go with them. Unit testing is a software engineering
  25. methodology that makes it easier to build correct code. Every
  26. method in every class should have a set of tests to verify
  27. that they work correctly. Mono also needs a testing framework
  28. to make it easy to write and run lots of tests.
  29. In some classes, we might also provide standalone tests because of
  30. some reasons such as too huge testcases, another downloading and so on.
  31. (For example, managed XSLT has standalone test which downloads and
  32. expands some megabytes of OASIS test suite.)
  33. Here I list them up as long as I know. If you are going to add another
  34. standalone tests, please add one line here. It is also recommended that
  35. you add some notes on how to build and run tests.
  36. <ul>
  37. * Mono.Data/test/
  38. * System.Data/Test, and some individual ADO.NET libraries:
  39. there are some standalone tests. See the bottom of <a href="ado-net.html">
  40. ADO.NET page</a> for detail.
  41. * System.Web/Test/TestMonoWeb : see README
  42. * System.Web.Services/Test/standalone : see README
  43. * System.Windows.Forms/SWFTest/
  44. * System.XML/Test/System.Xml/standalone_tests : see README
  45. * System.XML/Test/System.Xml.Schema/standalone_tests : see README
  46. * System.XML/System.Xml.Serialization/standalone_tests/
  47. * System.XML/Test/System.Xml.Xsl/standalone_tests : see README
  48. * Commons.Xml.Relaxng/Test/standalone_tests : see README
  49. </ul>
  50. ** Getting started
  51. If you are new to writing NUnit tests, there is a template you may use
  52. to help get started. The file is:
  53. <b>mcs/class/doc/TemplateTest.cs</b>
  54. Save a copy of this file in the appropriate test subdirecty
  55. (see below), and replace all the {text} markers with
  56. appropriate code. Comments in the template are there to guide
  57. you. You should also look at existing tests to see how other
  58. people have written them.
  59. mcs/class/corlib/Test/System.Collections/CollectionBaseTest.cs
  60. is a small one that might help.
  61. The directory that will contain your new file depends on the
  62. assembly/namespace of the class for which you are creating the
  63. tests. Under mcs/class there is a directory for each
  64. assembly. In each assembly there is a Test directory,
  65. e.g. mcs/class/corlib/Test. In the Test directory there are
  66. sub-directories for each namespace in the assembly,
  67. e.g. mcs/class/corlib/Test/Sytem. Put your new test file in
  68. the appropriate sub-directory under Test for the class you are
  69. testing.
  70. Once all of that is done, you can do a 'make test' from the top mcs
  71. directory. Your test class needs also to be listed in the
  72. .sources file at the top of the Test directory.
  73. * Tips on writing Unit tests.
  74. You should look at the <a href="http://nunit.org">NUnit documentation</a>,
  75. as it is a fantastic product, and includes fantastic documentation,
  76. but here are some tips for those of you who are already reading
  77. this web page.
  78. ** Provide an unique error message for Assert()
  79. Include an unique message for each Assert() so that when the assert
  80. fails, it is trivial to locate it in the source. Otherwise, it may be
  81. difficult to determine which part of the test is failing. A good way
  82. to ensure unique messages is to use something like #A01, #A02 etc.
  83. Ok:
  84. <pre>
  85. AssertEquals("array match", compare[0], i1[0]);
  86. AssertEquals("array match", compare[1], i1[1]);
  87. AssertEquals("array match", compare[2], i1[2]);
  88. AssertEquals("array match", compare[3], i1[3]);
  89. </pre>
  90. Excellent:
  91. <pre>
  92. AssertEquals("#A01", compare[0], i1[0]);
  93. AssertEquals("#A02", compare[1], i1[1]);
  94. AssertEquals("#A03", compare[2], i1[2]);
  95. AssertEquals("#A04", compare[3], i1[3]);
  96. </pre>
  97. Once you used such a number in an Assert(), don't change it later on -
  98. people might use it it identify the test in bug reports or in mailing
  99. lists.
  100. ** Use AssertEquals() to compare things, not Assert().
  101. Do not compare two values with Assert() - if the test fails,
  102. people have no idea what went wrong while AssertEquals()
  103. reports the failed value.
  104. Ok:
  105. <pre>
  106. Assert ("A01", myTicks[0] == t1.Ticks);
  107. </pre>
  108. Excellent:
  109. <pre>
  110. AssertEquals ("A01", myTicks[0], t1.Ticks);
  111. </pre>
  112. ** Test your test with the Microsoft runtime
  113. If possible, try to run your testsuite with the Microsoft runtime on
  114. .NET on Windows and make sure all tests in it pass. This is especially
  115. important if you're writing a totally new testcase - without this
  116. check you can never be sure that your testcase contains no bugs ....
  117. Don't worry if you're writing your test on Linux, other people can
  118. test it for you on Windows.
  119. Sometimes you may discover that a test doesn't show the expected
  120. result when run with the Microsoft runtime - either because there is a
  121. bug in their runtime or something is misleading or wrong in their
  122. documentation. In this case, please put a detailed description of the
  123. problem to mcs/class/doc/API-notes and do also report it to the
  124. <a href="mailing-lists.html">mailing list</a> - we'll forward this to the
  125. Microsoft people from time to time to help them fix their documentation
  126. and runtime.
  127. ** Unit tests.
  128. Why do unit testing? It becomes simple to run automated tests
  129. for the whole library. Unit tests are a safety net - you can
  130. change part of the code and verify that you haven't broken
  131. anything. Ideally, tests are written before the actual library
  132. code itself. And every time a bug is discovered, a test should
  133. be written to demonstrate the bug and its fix. Then, if
  134. you ever reintroduce the bug, you will know immediately. For
  135. more info, read <a
  136. href="http://junit.sourceforge.net/doc/testinfected/testing.htm">
  137. JUnit Test Infected: Programmers Love Writing Tests</a>.
  138. ** Getting Started
  139. We welcome all contributions to the Class Libary Test Suite.
  140. There is information to help you get started in CVS at
  141. mcs/class/doc/NUnitGuidelines. Once you have written your test, please
  142. post it to <a href="mailing-lists.html">mono-list</a>.
  143. Someone will make sure to add the file or apply the patch as
  144. appropriate. If you plan to be an on-going contributor and
  145. would like to get cvs account, email <a href="mailto:[email protected]">miguel</a>.
  146. Normally, after you send a couple of well-written new files
  147. and/or patches to the list, you will be given cvs access.
  148. <a name="compiler"></a>
  149. * Compiler tests
  150. Mono ships with three compilers: C#, VB.NET and JScript. The
  151. tests are ran by running the makefile target `make
  152. run-test-local' in the appropriate directory.
  153. The C# compilation tests live in mcs/tests, and the C# error
  154. tests live in mcs/errors.
  155. The VB.NET compilation tests live in mcs/btests.
  156. <a name="runtime"></a>
  157. * Runtime Tests
  158. These tests verify the virtual machine, to run these tests, do:
  159. <pre>
  160. cd mono/mono/tests
  161. make test
  162. </pre>
  163. <a name="aspnet"></a>
  164. * ASP.NET tests
  165. XSP, the Mono ASP.NET server has tests for ASP.NET pages. It uses
  166. <a href="http://nunitasp.sourceforge.net">NUnitAsp</a>. Right now
  167. it only has standalone tests, ie., tests that do not need their own
  168. global.asax or web.config files.
  169. If you want to run them, get the xsp CVS module and install it. Then:
  170. <pre>
  171. cd xsp/nunit-tests
  172. make
  173. cd standalone
  174. xsp
  175. </pre>
  176. And from another terminal:
  177. <pre>
  178. cd xsp/nunit-tests/standalone
  179. nunit-console standalone-tests.dll
  180. </pre>
  181. <a name="ws"></a>
  182. * Web Services tests
  183. The Test directory for the System.Web.Services assembly contains a
  184. standalone test suite for testing web services. It tests:
  185. <ul>
  186. <li>Proxy generation using the wsdl tool</li>
  187. <li>Access to web services using the generated client proxies</li>
  188. <li>Execution of web services in the server</li>
  189. </ul>
  190. This suite not only tests web services running on XSP, but it can also test
  191. services running on other platforms and that are available in internet. This
  192. will help track down interoperability issues.
  193. To build the test suite, just run:
  194. <pre>
  195. cd mcs/class/System.Web.Services/Test/standalone
  196. xsp --root server
  197. </pre>
  198. And from another terminal:
  199. <pre>
  200. cd mcs/class/System.Web.Services/Test/standalone
  201. make
  202. nunit-console testclient.dll
  203. </pre>
  204. This will download the wsdl documents, generate the proxies, build a dll with
  205. the proxies, and build the nunit tests. Then you can use nunit-console or
  206. gnunit to run the tests (the nunit dll is testclient.dll).
  207. Read the README file in mcs/class/System.Web.Services/Test/standalone for
  208. more info.