Subject Re: After UDF exception, the current connection stops working
Author Roman Rokytskyy
Hi,

> Your test case did not really cover what I reported. Below is
> a modification of your test case. (I am sorry I don't know how
> to write junit test case):

Sorry, probably I understood you wrong.

>
>
> Object tmp = rs.getObject (1); //This should
> cause null pointer exception

I modified test case, but it does not cause NullPointerException. See CVS.

As to the writing test cases. Concept is very simple. JUnit test case
has to implement junit.framework.Test interface (usually people extend
junit.framework.TestCase class, I assume you do the same). Each test
case has its setup method (protected void setUp()) where some stuff to
initialize test case is performed. Also it has a cleanup method
(protected void tearDown()) that is called after test case execution
to clean everything that was setup by the setUp() method. Then all
public void methods that start with "test" are considered as a test case.

Example:

public class MyTestCase extends junit.framework.TestCase {
public MyTestCase(String name) {
super(name);
}

private int testValue;

protected void setUp() {
testValue = 5;
}

protected void tearDown() {
testValue = 0;
}

public void testArithmetic() throws Exception {
int a = 2;
int b = 3;
int c = a + b;
assertTrue("Value should be correct.", c == testValue);
}
}

In order to execute test case you have to use "runner". There are two
runners: Swing-based and text-based. I prefer latter.

public class RunMyTestCase {
public void main(String[] args) throws Exception {
junit.textui.TestRunner.run(MyTestCase.class);
}
}

This code will create instance of MyTestCase class, it will call
setUp() method, then testArithmetics() and then tearDown() method.
Such sequence is kept for each method that starts with "test".

If you want to create test cases for JayBird, you should extend
org.firebirdsql.common.FBTestBase. Do not forget to override setUp()
and tearDown() methods like this:

protected void setUp() throws Exception {
super.setUp();
// your code to setup test case
}

protected void tearDown() throws Exception {
// your cleanup code
super.tearDown();
}

This guarantees you that you will have fresh database before executing
your test case.

Best regards,
Roman Rokytskyy