db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "IntroToJUnit" by JohnHEmbretsen
Date Mon, 13 Nov 2006 11:01:53 GMT
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:
Improved some assertXXX examples, and resources section.

------------------------------------------------------------------------------
  assertEquals(expected, rValue, 0.0);
  }}}
  
+ '''assertTrue'''
+ 
+ Takes a boolean argument. Use this when the expected result is true.
+ {{{
+ // verify that autocommit is on
+ assertTrue(getConnection().getAutoCommit());
+ }}}
+ 
+ 
  '''assertFalse'''
  
- Takes a boolean argument.  Could use in place of assertTrue(boolean)
+ Takes a boolean argument.  Use this when the expected result is false.
  {{{
- int result = val1 + val2;
- assertFalse(result == 10);
+ // there should be no more rows in this ResultSet
+ assertFalse(rs.next());
+ }}}
+ 
+ '''assertNull'''
+ 
+ Takes an object with an optional second argument, the String message. Use this when you
expect an object to be null.
+ 
+ {{{
+ // expecting SQL NULL in column 2 of this row
+ assertNull("Second column should be null", rs.getString(2));
  }}}
  
  '''assertNotNull'''
  
- Takes an object with an optional second argument, the String message.
+ Takes an object with an optional second argument, the String message. Use this when you
want to accept anything but null.
  {{{
- s2 = new String("string1");
- assertNotNull("Fail: Object s2 is null. ", s2);
+ String importantText = rs.getString(1);
+ assertNotNull("Fail: Important text is null! ", importantText);
  }}}
  
  '''assertNotSame'''
@@ -577, +595 @@

  assertNotSame("Fail: string1 is the same as s2", "string1", s2)
  }}}
  
- '''assertNull'''
- 
- Takes an object with an optional second argument, the String message.
- 
- {{{
- Object nullObj = null;
- assertNull("Fail:object was not null", nullObj);
- }}}
- 
- '''assertTrue'''
- 
- {{{
- int val1 = 5;
- int val2 = 6;
- int result = val2 - val1;
- assertTrue(result == 1);
- }}}
- 
  '''fail'''
  
- Fail takes one argument, the String message output and is used to fail a test.
+ Fail takes one argument, the String message output, and is used to fail a test.
  
  Why would you want to use this?  For instance if you are performing some
+ action that should throw an exception, and you want the test to fail if 
+ no exception was thrown.
- action that should throw an exception and you don't know whether the exception
- was thrown or not.  Since JUnit does not output exceptions, just failures,
- use fail to fail the test if the exception was not thrown.
  {{{
  try {
       // for the value TWO_RADIANS, this method should throw
@@ -612, +611 @@

  					+ TWO_RADIANS);
      } catch (SQLException sqlE) {
         // "ERROR 22003: The resulting value is outside the range for the data type DOUBLE.";
+     }
  }}}
  
  == JUnit tests and the Derby test harness ==
@@ -626, +626 @@

  
  [http://junit.sourceforge.net/doc/faq/faq.htm JUnit FAQ]
  
- The Derby wiki
+ The Derby wiki:
   * ["DerbyJUnitTesting"]
   * DerbyJunitTestConfiguration, a new page that is under construction 
  
- Eclipse JUnit Getting Started
+ Eclipse JUnit Getting Started:
  
- Open Eclipse Help from the main menu item, select the Java Development User Guide book,
Getting Started >> Basic tutorial, Writing and running JUnit tests.
+  * Open Eclipse Help from the main menu item, select the Java Development User Guide book,
Getting Started >> Basic tutorial, Writing and running JUnit tests.
  
- [http://open.ncsu.edu/se/tutorials/junit/ Eclipse JUnit Tutorial]
+  * [http://open.ncsu.edu/se/tutorials/junit/ Eclipse JUnit Tutorial]
  
+ Other articles:
+ 
- [http://www.javaworld.com/jw-12-2000/jw-1221-junit.html Javaworld JUnit article]
+  * [http://www.javaworld.com/jw-12-2000/jw-1221-junit.html Javaworld JUnit article]
  
+ Tools:
+ 
+  * [https://issues.apache.org/jira/browse/HARMONY-1960 Perl script to help detect potential
issues and conflicts with "best practice"]
+ 

Mime
View raw message