Reputation: 5614
In Junit, I know there is a @beforeclass , @before annotation, do we have a annotation or design, allow us to write a method to run ONLY once before the whole testing process?
we have a script, which setup some database data (config, static, lookup table etc.....) for the test, but its too expensive to run before each individual test, we would like it to set it, only once before start running any test.
thanks!
Upvotes: 1
Views: 1206
Reputation: 10762
Since you tagged your question with maven
, I'll go this way: you could use the pre-integration-test
phase to run this one-time expensive script (symmetrically, you clean up in post-integration-test
).
You could use exec-maven-plugin for this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<id>some-execution</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable><!-- runnable command or file name here --></executable>
</configuration>
</plugin>
JUnit does not have this kind of annotation, because it does not make any assumption about the environment: its goal is to test one class at a time in an isolated manner.
Upvotes: 3
Reputation: 111
DBUnit provides exactly the thing you are looking for. Its a JUnit extension only.
Upvotes: 1