For my JUnit 4 tests, a handful of database inserts have to be performed by code. However, the application framework has some overhead, which makes this step really slow.
To save time, I tried to run this initial step only one time before the first test execution. The tests perform read operations only, no writes, so the risk of test side effects is minimal.
Using @Transactional however, all inserted data is reverted after the first test, causing test failures or false positives for all other tests.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { ... })
@Transactional
public class DatabaseFilterTest {
static boolean setUpIsDone = false;
@Before
public void setUp() {
...
if (!setUpIsDone) {
// do the setup
prepareData();
setUpIsDone = true;
}
}
With JUnit 4, is there a way to perform the transaction rollback at the end, after all tests have been run?