February Meeting

From DojoWiki

Jump to: navigation, search

The February meeting will be 6:00PM, March 1st at the [Technology Council]

We'll be doing something associated with unit testing for Database applications.

Here are three topics that I think we can break the meeting down by.

  1. Testing DB and External Libraries
  2. Defect Prevention vs Design Evolution (Test Last vs Test First)
  3. Dependency Injection (removing dependencies from classes so they can be tested as units vs as a whole system).
    1. Here is a good post on Dependency Injection in Ruby http://onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc
def test_Insert
  topic_desc = "Database"
  topic = Topic.create "topic_desc" => topic_desc, "parent_id" => 0
  assert_not_nil topic
  assert_equal topic_desc, topic.topic_desc
  assert_equal 0, topic.parent_id
end

Now in Java

import java.sql.* ;
import org.junit.*;

class TestJdbcInsert
{
  public void testInsert( )
  {
  try
  {
    // Load the database driver
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;

    // Get a connection to the database
    Connection conn = DriverManager.getConnection( "jdbc:odbc:Database" ) ;

    // Get a statement from the connection
    Statement stmt = conn.createStatement() ;

    // Execute the Update
    int rows = stmt.executeUpdate( "insert into topics values
      ('Programming', 0" ) ;

    assert.IsEqual( 1, rows ) ;

    // Close the statement and the connection
    stmt.close() ;
    conn.close() ;
  }
  catch( SQLException se )
  {
    assert.fail();

    // Loop through the SQL Exceptions
    while( se != null )
    {
    System.out.println( "State : " + se.getSQLState() ) ;
    System.out.println( "Message: " + se.getMessage() ) ;
    System.out.println( "Error : " + se.getErrorCode() ) ;

    se = se.getNextException() ;
    }
  }
  catch( Exception e )
  {
    assert.fail();
  }
}
}
Personal tools