What are the assertXXX() methods. The last in this series for a bit.
After reading the other posts in this series, the main thing that is
left is to list the different assertXXX() methods.
They are:
assertEquals(expected, actual, msg)
assertNotEquals(expected, actual, msg)
assertNull(actual, msg)
assertNotNullactual, msg)
assertSame(expected, actual, msg)
assertNotSame(expected, actual, msg)
assertTrue(actual, msg)
assertFalse(actual, msg)
Some key points.
1.) All of these are methods, so to use them in your tests you do, for example:
self~assertTrue(.true)
If you are hazy on objects, just think of that as a routine with a
mandatory prefix of 'self~'
2.) Where you have expected and actual args, expected always comes first.
val = 2 + 3
self~assertSame(5, val)
5 is expected, val is the actual.
3.) Where you just have the actual arg, it is the actual. grin
val = .true
self~assertTrue(val)
or
val = 2 + 3
self~assertTrue(val == 5)
4.) As the above shows, there are usually several ways to write the
same assertion. Pick what you are comfortable with.
5.) All the assertions have an optional 'message' argument that is the
last arg. The message is printed out if the assertion fails.
Here is an example:
::method test_addition
val = 2 + 3
self~assertSame(6, val, '2 plus 3 must equal 6')
and the output:
[failure] [20080701 09:19:45.455000]
Test: TEST_ADDITION
Class: STREAM.testGroup
File: C:\work.ooRexx\ooRexxUnit\3.2.0\ooRexx\STREAM.testGroup
Line: 82
Failed: assertSame
Expected: [[6], identityHash=535894080]
Actual: [[5], identityHash=535906054]
Message: 2 plus 3 must equal 6
The intention of the message is to give some idea about what the test
is testing. Here we see that the test writer has used some faulty
logic.
Without the message and a non-descriptive test name we would see:
[failure] [20080701 09:22:45.367000]
Test: TEST_001
Class: STREAM.testGroup
File: C:\work.ooRexx\ooRexxUnit\3.2.0\ooRexx\STREAM.testGroup
Line: 82
Failed: assertSame
Expected: [[6], identityHash=535894080]
Actual: [[5], identityHash=535906054]
which, if you were not the one that wrote the test, might leave you
clueless. Then if you look at the test you would see:
::method test_001
val = 2 + 3
self~assertSame(6, val)
And you might really wonder what the test writer had in mind for this
test in the STREAM test group.
In general you don't need a message. But, it can help clarify what
the test is about by using a message that states what is expected.
6.) The assertXXX() methods are pretty self explanatory, with maybe
this exception:
assertSame() and assertEquals().
assertSame() (and assertNotSame()) assert that 2 things are stictly equal.
5 == 5
assertEquals() (and assertNotEquals()) assert that 2 things are loosely equal.
'dog ' = 'dog'
equals is also used to test if 2 collections are loosely equal.
a1 = .array~of(1, 2, 3)
a2 = .array~of(1, 2, 3)
self~assertEquals(a1, a2)
assertNull() and assertNotNull() might also need some explaining.
They test if the actual is .nil (or not .nil).
7.) The assertXXX() methods are located in the OOREXXUNIT.CLS file.
Since this is open source you can always browse the file to see what
assertXXX() methods are available to you. Which is what I do since I
can never remember them and no one has produced easy to find
documentation for the framework.
OOREXXUNIT.CLS is located in the framework subdirectory:
C:\ooRexxUnit.3.2.0dir framework\OOREXXUNIT.CLS
Volume in drive C has no label.
Volume Serial Number is B4C0-DCBA
Directory of C:\ooRexxUnit.3.2.0\framework
05/12/2008 01:15 PM65,321 OOREXXUNIT.CLS
-
Speaking of doc etc., in the misc subdirectory there are some sample
test group files. Looking at those should be helpful. I believe I
tried to comment them well.
C:\ooRexxUnit.3.2.0dir misc
Volume in drive C has no label.
Volume Serial Number is B4C0-DCBA
Directory of C:\ooRexxUnit.3.2.0\misc
01/18/2008 10:41 AM 5,755 SampleOLEObject.testGroup
01/16/2008 01:40 PM 5,638 Simplest.testGroup
01/16/2008 04:17 PM 5,775 SimpleWithOneTimeSetup.testGroup
01/16/2008 04:28 PM 5,609 SimpleWithSomeSetup.testGroup
There is also doc and more examples in the framework directory.
However, those docs and examples are from the original ooRexxUnit
framework.
The framework we are using here is the ooTest framework, which sits on
top of ooRexxUnit. The ooRexxUnit doc does not necessarily apply to
ooTest. And, I have made changes to ooRexxUnit, but have not been
rigorous about maintaining the ooRexxUnit doc and examples.
Armed with this series of posts, I think that anyone who can program
in Rexx and is using ooRexx to some degree can begin writing test
cases for the ooRexx interpreter.
Ask questions when you get stuck. Contribute test cases to the
project. Earn yourself the status of a committer.
About that last sentence.