Rollback JUnit Tests in Deltaspike

681 Views Asked by At

I am using Apache Deltaspike with OpenWebBeans for CDI in a Java SE project. I've used Spring Data JPA in a Java EE project and it was easy enough to setup unit tests that didn't commit data to the database by adding the @Transactional annotation above the class or test methods. However, I haven't been able to find an equivalent technique with Deltaspike.

Apart from manually rolling back data after each test or by deleting and re-creating the database each time a test is run, is there any way to specify that each unit test should rollback data changes after completing?

My unit tests look somewhat like the following:

@RunWith(CdiTestRunner.class)
@Transactional // has no effect
public class FooUnitTest {
    @Inject
    private FooRepository fooRepository;

    @Test
    @Transactional // no effect either
    public void testFoo() {
        Foo foo = new Foo();
        fooRepository.save(foo); // foo is persisted even outside the test
    }
}

@Repository
public interface FooRepository extends EntityRepository<Foo, Integer> { }
0

There are 0 best solutions below