Manjula G Kutty wrote:
Hi,

I'm very new to the junit testing. So I picked lang/currentof.java as my first test to convert to junit. I did it with the very little knowledge I have and also with the help of the Wiki. I got the test running to some extend but then I get some errors on the testUpdate. The error says "Invalid cursor state" . I tried using printf to see how the control goes and I could see the number of rows expected and got are 0. So it should come out of the verifycount method, but it is not. There may be 3 reasons for this. Either I didn't understand the test fully or did something wrong while converting or there may be bug . Can someone please review the attached code(I know it is not a very clean code) and let me know what went wrong??

One of the possibly unexpected facts about Junit when coming from the old derby test harness is understanding the setup and tearDown methods of a test class. A test class contains fixtures, methods that start with 'test' which are individual test cases. The setup and tearDown in a test class are run for *each* fixture, thus I think twice in this class, once for testUpdate() and once for testDelete(). I think a common mistake is to assume they are run once for all the fixtures. Could that be the case here?

Another issue is that the order of fixtures is not guaranteed when adding a suite using MyTest.class. This is intentional since fixtures should be standalone test cases, thus if your test depends on testUpdate() running before testDelete() you may see intermittant problems.

One more question where will the test database gets created? Even the test fails will the teardown method deletes all tables? If so is there a mechanism to access the database or copy the database instance when the test went wrong?

Nothing exists at the moment, apart from working in a debugger. Please feel free to implement something.

Dan.

Reply via email to