@@ -26,17 +26,31 @@ code::
2626UnitTest.gui
2727::
2828
29- METHOD:: runTest
30- Run a single test for methodName .
29+ METHOD:: run
30+ Run all methods whose names begin with code::test_:: .
3131
32- ARGUMENT:: methodName
33- Should have the format code::"TestPolyPlayerPool:test_prepareChildrenToBundle"::
32+ code::
33+ TestUnitTest.new.run;
34+ ::
35+
36+ ARGUMENT:: reset
37+ If code::true::, first runs link::#*reset:: on the class.
38+
39+ ARGUMENT:: report
40+ If code::true::, outputs the test results.
41+
42+ METHOD:: runTest
43+ Run a single test method.
3444
3545code::
3646UnitTest.reset;
3747UnitTest.runTest("TestUnitTest:test_assert");
3848::
3949
50+ ARGUMENT:: methodName
51+ A link::Classes/String:: referring to the class and test method
52+ within it, e.g. code::"TestPolyPlayerPool:test_prepareChildrenToBundle"::.
53+
4054
4155METHOD:: runAll
4256runs all subclasses of UnitTest
@@ -47,133 +61,135 @@ UnitTest.runAll;
4761::
4862
4963
50- METHOD:: runTestClassForClass
51- runs testclass for a class
52-
53- ARGUMENT:: class
54- the class
55-
56- ARGUMENT:: reset
57- reset UnitTest environment
58-
59- ARGUMENT:: report
60- report on pass/fail
61-
62-
63-
64-
65-
66-
6764INSTANCEMETHODS::
6865
69- METHOD:: run
70- All method names that start with test_ are invoked.
71-
72- ARGUMENT:: reset
73- (describe argument here)
74-
75- ARGUMENT:: report
76- (describe argument here)
77-
78- returns:: (describe returnvalue here)
66+ METHOD:: runTestMethod
67+ Run a single test method of this class
7968
8069code::
81- TestUnitTest.new.run ;
70+ TestUnitTest.new.runTestMethod(TestUnitTest.findMethod(\test_assert)) ;
8271::
8372
73+ ARGUMENT:: method
74+ the method to run
8475
76+ returns:: (describe returnvalue here)
8577
78+ PRIVATE:: s, run, findTestMethods, setUp, tearDown
8679
8780
88- METHOD:: runTestMethod
89- Run a single test method of this class
81+ METHOD:: assert
9082
91- ARGUMENT:: method
92- the method to run
83+ Asserts that an expression must be true.
9384
9485code::
95- TestUnitTest.new.runTestMethod(TestUnitTest.findMethod(\test_assert));
86+ this.assert(2 == 2, "passes");
87+ this.assert(2 == 2.00001, "fails");
9688::
9789
98- returns:: (describe returnvalue here)
90+ argument:: boolean
91+ A boolean, where code::true:: means that the test is passed.
9992
100- PRIVATE:: assert, assertArrayFloatEquals, asynchAssert, tearDown, setUp, assertEquals, failed, passed, assertFloatEquals, s, ifAsserts, findTestMethods, wait, bootServer
93+ argument:: message
94+ A message describing the purpose of the assertion, e.g. code::"foo
95+ should be less than bar"::.
96+ Posted if code::report:: is true.
10197
98+ argument:: report
99+ Reports the result of the test if code::true::.
102100
103- SECTION:: Writing tests by subclassing UnitTest
101+ argument:: onFailure
102+ If not code::nil::, a failure stops the tests and evaluates this function.
104103
105- code::
106- YourClass.test
107- ::
108- Runs the test class for code::YourClass::, which is assumed to be named code::TestYourClass::.
104+ METHOD:: assertEquals
109105
110- If no test class if found it politely declines.
106+ Asserts that an expression code::a:: is equal to the value code::b::,
107+ where equality is determined according to code::a::'s implementation
108+ of code::==::.
111109
112- note::
113- UnitTests for the Common library classes are kept in the CommonTests quark. This enables you to easily install and uninstall these tests.
110+ code::
111+ this.assertEquals(2 + 2, 4, "passes");
112+ this.assertEquals(2 + 2, 5, "fails");
114113::
115114
115+ argument:: a
116+ the experimentally produced value
116117
117- Make sure to implement the methods code::setUp:: and code::tearDown::. They will be called before and after the test.
118-
119- METHOD:: assert
120-
121- argument:: test
122- Make sure that this returns a boolean, where code::true:: means that the test is passed.
118+ argument:: b
119+ the expected value
123120
124121argument:: message
125- posted if report is true.
122+ A message describing the purpose of the assertion, e.g.
123+ code::"Adding two numbers should return their sum."::.
124+ Posted if code::report:: is true.
125+
126+ argument:: report
127+ Reports the result of the test if code::true:: (default is code::true::)
126128
127129argument:: onFailure
128130If not code::nil::, a failure stops the tests and evaluates this function.
129131
130- code::
131- UnitTest.new.assert(2 == 2, "Two does equal two.");
132- UnitTest.new.assert(2 == 2.00001, "Two does equal two.");
133- ::
134-
135132METHOD:: assertFloatEquals
136133
137- Make sure that the two floats code::a:: and code::b:: equal within a given range (code::within::).
134+ Asserts that an expression code::a:: returning a float is within a
135+ given range (code::within::) of being equal to code::b::.
138136
137+ code::
138+ this.assertFloatEquals(2, 2.0001, "Pass since 2 is close enough to 2.0001.", 0.001);
139+ this.assertFloatEquals(2, 2.0001, "Fail since 2 isn't close enough to 2.0001.", 0.0001);
140+ ::
139141
140142argument:: a
141- a float
143+ the experimentally produced float value
142144
143145argument:: b
144- a float
146+ the expected float value
145147
146148argument:: message
147- posted if report is true.
149+ A message describing the purpose of the assertion, e.g.
150+ code::"Adding two numbers should return their sum."::.
151+ Posted if code::report:: is true.
152+
153+ argument:: within
154+ The range within which code::a:: must be of code::b:: in
155+ order for the test to pass.
156+
157+ argument:: report
158+ Reports the result of the test if code::true:: (default is code::true::)
148159
149160argument:: onFailure
150161If not code::nil::, a failure stops the tests and evaluates this function.
151162
152163
164+ METHOD:: assertArrayFloatEquals
165+ Make sure that the two arrays of floats code::a:: and code::b:: equal within a given range (code::within::).
153166
154167code::
155- UnitTest.new.assertFloatEquals( 2, 2.00001, "Two does equal two. ", 0.00001 );
156- UnitTest.new.assertFloatEquals( 2, 2.001, "Two does equal two. ", 0.0001);
168+ this.assertArrayFloatEquals([ 2, 3] + 0.0001, [2, 3], "Pass since pairs of floats are close enough ", 0.001 );
169+ this.assertArrayFloatEquals([ 2, 3.0001], [2, 3], "Fail since pairs of floats aren't both close enough ", 0.0001);
157170::
158171
159- method:: assertArrayFloatEquals
160- Make sure that the two arrays of floats code::a:: and code::b:: equal within a given range (code::within::).
161-
162172argument:: a
163- an code::Array:: of floats
173+ the experimentally produced value, which is an code::Array:: of floats
164174
165175argument:: b
166- an code::Array:: of floats
176+ the code::Array:: of float values expected
167177
168178argument:: message
169- posted if report is true.
179+ A message describing the purpose of the assertion, e.g.
180+ code::"Arrays foo and bar should be equal."::.
181+ Posted if code::report:: is true.
182+
183+ argument:: within
184+ The range within which each item of code::a:: must be of the
185+ corresponding item in code::b:: in order for the test to pass.
186+
187+ argument:: report
188+ Reports the result of the test if code::true:: (default is code::true::)
170189
171190argument:: onFailure
172191If not code::nil::, a failure stops the tests and evaluates this function.
173192
174- code::
175- UnitTest.new.assertArrayFloatEquals([2, 3], [2, 3] + 0.00001, "Same Floats", 0.000001);
176- ::
177193
178194METHOD:: ifAsserts
179195Make a further assertion only if it passed, or only if it failed.
@@ -210,14 +226,31 @@ code::
210226)
211227::
212228
229+ METHOD:: passed
230+ Register a passed test.
231+
232+ code::
233+ this.passed(message: "this passed");
234+ ::
235+
213236METHOD:: failed
214- call failure directly .
237+ Register a test failure .
215238
216239code::
217- UnitTest.new.passed (message: "this passed ");
240+ this.failed (message: "this failed ");
218241::
219242
220- SUBSECTION:: UnitTest (sub)class example.
243+ EXAMPLES::
244+
245+ Write tests by subclassing UnitTest, and defining methods whose names
246+ begins code::test_::. Each test method will be called from a fresh
247+ instance of the subclass.
248+
249+ If you implement the methods code::setUp:: and code::tearDown:: in
250+ your test class, they will be called before and after every test.
251+ This can help to eliminate repetitive code, and makes it easier to
252+ maintain your tests by ensuring that they all run under the same set
253+ of conditions.
221254
222255code::
223256TestYourClass : UnitTest {
@@ -229,9 +262,7 @@ TestYourClass : UnitTest {
229262 }
230263
231264 test_yourMethod {
232-
233- // every method named test_
234- // will be run
265+ // every method whose name begins with "test_" will be run
235266
236267 this.assert( 6 == 6, "6 should equal 6");
237268
0 commit comments