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/07/05 17:25:03 UTC

[Db-derby Wiki] Update of "ConvertOldTestToJunitTips" by KatheyMarsden

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 KatheyMarsden:
http://wiki.apache.org/db-derby/ConvertOldTestToJunitTips

------------------------------------------------------------------------------
     * run {{{derbyall}}} - check for no (new) failures
     * {{{svn diff}}} to create a patch & attach to the jira issue along with the output of {{{svn stat}}}
  
+ === Common mistakes ===
+    * Not using the utility methods that have already been created.  
+      There are quite a few built in utility methods which can be used in tests.  Before you get started, study the     [http://db.apache.org/derby/javadoc/testing/org/apache/derbyTesting/junit/package-summary.html derbyTesting.junit javadoc] for utility methods and decorators that are already available.  Tests using JDBC should inherit from [http://db.apache.org/derby/javadoc/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.html BaseJDBCTestCase] and can use all of the utility methods available in that class such as getConnection, openDefaultConnection, createStatement, assertSQLState, usingDerbyNetClient etc. Some of the common  methods used in  [http://db.apache.org/derby/javadoc/testing/org/apache/derbyTesting/junit/JDBC.html JDBC] are assertFullResultSet for checking result sets returned, and the vmSupportsXXX() calls for jvm specific behavior. 
+    * Misusing the utility methods.  
+      Be careful of the order of the arguments of the utility methods.  For example in [http://db.apache.org/derby/javadoc/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.html#assertSQLState(java.lang.String,%20java.lang.String,%20java.sql.SQLException)  assertSQLState] the expected exception comes first. Even though the test might pass if the arguments are reversed, if it were to ever fail the message would not make sense.
+    * Not using the utility methods to get a connection. 
+      Normally to get a connection to the default database, you should use [http://db.apache.org/derby/javadoc/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.html#getConnection() getConnection()] This is a single connection that is reused so if you call getConnection twice, you will get the same connection.  If you want a secondary connection, use [http://db.apache.org/derby/javadoc/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.html#openDefaultConnection() openDefaultConnection]
+    * Not removing the old test files. 
+      You should remove the old test files, canons and remove the old test from its suite. ant clobbber before you build, to make sure their are no residual dependencies on the old test files.
+  
+ 
+ 
+ 
+ 
  == When writing tests is there a short cut to creating the ResultSet two dimensional arrays? ==
  You can use org.apache.derbyTesting.junit.Utilities.showResultSet(ResultSet rs) to print out the two dimensional array and then cut and paste into your code.