Currently transactions inside tests must be manually created. It's quite useful to have automatic transaction creation in tests using @ExpectedDataSet:
@Test
@DataSet("users.yml")
@ExpectedDataSet(value = "expectedUser.yml",ignoreCols = "id") //<1>
public void shouldAssertDatabaseUsingExpectedDataSet() {
User user = (User) em().
createQuery("select u from User u where u.id = 1").
getSingleResult();
assertThat(user).isNotNull();
tx().begin();
em().remove(user);
tx().commit();
}
As no assertion is made inside the test we could have begin/commit handled automatically before and after test (but before expectedDataSet comparison):
@Test
@DataSet("users.yml", transactional=true)
@ExpectedDataSet(value = "expectedUser.yml",ignoreCols = "id") //<1>
public void shouldAssertDatabaseUsingExpectedDataSet() {
User user = (User) em().
createQuery("select u from User u where u.id = 1").
getSingleResult();
assertThat(user).isNotNull();
em().remove(user);
}
Currently transactions inside tests must be manually created. It's quite useful to have automatic transaction creation in tests using @ExpectedDataSet:
As no assertion is made inside the test we could have begin/commit handled automatically before and after test (but before expectedDataSet comparison):