Just some of reminders about JUnit tests.

1) BaseJDBCTestCase is the parent class for all JDBC tests in derby, it already has a field to hold a single connection for a fixture, which is the typical case for most tests. Thus you don't need to put another Connection field in your test, just use the utility methods:

E.g.
  public void testSomething() {
   Statement s = createStatement();
   ...
  }

Not
   private Connection conn;
   public void testSomething() {
   conn = getConnection();
   Statement s = conn.createStatement();
   ...
  }


2) There's no benefit to having a Statement field in your test.
E.g. with this:
  private Statement s;
  public void testOne() {
   ...
  }
  public void testTwo() {
   ...
  }

when running the tests two Statement objects will be created, not one since a new instance of the class will be created for each fixture. Instead use local variables in the fixture:

  public void testOne() {
   Statement s = createStatement();
   ...
   s.close();
  }



3) If you have a try catch block to assert some error code, then ensure there is a fail() assert in the try portion.

E.g.
    try {
      s.execute(sql);
      fail("error was expected");
   } catch (SQLException e) {
     assertSQLState("43234", e);
   }

without the fail() the fixture will incorrectly pass if executing the SQL statement does not thrown the expected error.

Thanks,
Dan.

Reply via email to