jeudi 2 mai 2019

Should I use @Transactional or @Rollback for DAO test classes?

I have a dao layer for my database. Now, I am writing some integration tests for it. I wonder if @Transactional or @Rollback should be used in a test class, as they both revert the changes to the database. Which one would be a good practice and in what conditions?

I tried using both of them and they both work in my case. I have a @Before annotated method in my class.

@RunWith(SpringRunner.class)
@AutoConfigureTestDatabase(replace = NONE)
@DataJpaTest
// @Transactional or @Rollback?
public class TestDao {

    @Autowired
    private ConcreteDao concreteDao;

    @Before
    public void cleanUp(){ . . . }

    @Test
    public void testSaveAllEntries(){ . . . }

    // and other tests
}

Aucun commentaire:

Enregistrer un commentaire