You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by Apache Wiki <wi...@apache.org> on 2007/03/01 11:16:33 UTC
[Db-derby Wiki] Update of "IntroToJUnit" by JohnHEmbretsen
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.
The following page has been changed by JohnHEmbretsen:
http://wiki.apache.org/db-derby/IntroToJUnit
The comment on the change is:
now using java parser (color coding) for code examples
------------------------------------------------------------------------------
The method to test must start with the prefix 'test', e.g. 'testAddMethod'.
Example of the simplest test case, containing only one test:
- {{{
+ {{{#!java
package junitdemo;
import junit.framework.TestCase;
@@ -187, +187 @@
class.
==== JUnit Fixture class with a Main method ====
- {{{
+ {{{#!java
package junitdemo;
import junit.framework.TestCase;
@@ -305, +305 @@
==== Running a Suite of Tests ====
{{{
+ #!java
package junitdemo;
import junit.framework.Test;
@@ -376, +377 @@
to this:
{{{
+ #!java
// only adds two tests to the suite
public static Test suite() {
TestSuite suite = new TestSuite();
@@ -403, +405 @@
own suite and adds tests from another class too.
{{{
+ #!java
package junitdemo;
import junit.framework.Test;
@@ -433, +436 @@
'''SuiteTest1J!UnitTest'''
{{{
+ #!java
package junitdemo;
import junit.framework.Test;
@@ -493, +497 @@
'''SuiteTest2J!UnitTest'''
{{{
+ #!java
package junitdemo;
import junit.framework.Test;
@@ -548, +553 @@
Overloaded for almost all primitive data types and the Object arguments.
{{{
+ #!java
double expected = java.lang.StrictMath.acos(testArcValues[i]);
double rValue = executeValues("ACOS", testArcValues[i]);
assertEquals(expected, rValue, 0.0);
@@ -557, +563 @@
Takes a boolean argument. Use this when the expected result is true.
{{{
+ #!java
// verify that autocommit is on
assertTrue(getConnection().getAutoCommit());
}}}
@@ -566, +573 @@
Takes a boolean argument. Use this when the expected result is false.
{{{
+ #!java
// there should be no more rows in this ResultSet
assertFalse(rs.next());
}}}
@@ -575, +583 @@
Takes an object with an optional second argument, the String message. Use this when you expect an object to be null.
{{{
+ #!java
// expecting SQL NULL in column 2 of this row
assertNull("Second column should be null", rs.getString(2));
}}}
@@ -583, +592 @@
Takes an object with an optional second argument, the String message. Use this when you want to accept anything but null.
{{{
+ #!java
String importantText = rs.getString(1);
assertNotNull("Fail: Important text is null! ", importantText);
}}}
@@ -591, +601 @@
Takes two objects with an optional third argument, the String message.
{{{
+ #!java
s2 = new String("string1");
assertNotSame("Fail: string1 is the same as s2", "string1", s2)
}}}
@@ -603, +614 @@
action that should throw an exception, and you want the test to fail if
no exception was thrown.
{{{
+ #!java
try {
// for the value TWO_RADIANS, this method should throw
// an SQLException in Derby