Actually, you were right that I should have asked this question on the JUnit
mailing list instead. But here's the solution we used.

We just derived a class from TestSetup. In setUp(), we open a database
connection and add the data we need for the tests. Then in tearDown(), we
delete the rows we added to the database and close the connection. This way,
we don't have to keep opening and closing the connection before each
individual testXXX() in our test case. Also, none of the tests depend on the
success or failure of any other test, so we didn't break the JUnit Best
Practices. :-)

Thanks for pointing me in the direction of TestSetup! It was pretty
elementary once I found out about that decorator.

> There are a few options:
>
> 1) There may be a way to use setUp() and tearDown() so that they are
> not run before and after every test.  (I'm sure Vincent can answer that

Don't be so sure ... :)

> more thoroughly.)  Maybe you can use a flag to indicate whether the
> connection already exists and therefore reuse it.
>

The only thing I can tell you is that I have seen this subject several times
on the egroups junit mailing list (http://www.egroups.fr/group/junit) but I
never paid attention to the solution as I've never had the chance to use
that type of construction.

Vincent.

Reply via email to