【发布时间】:2017-08-01 23:05:18
【问题描述】:
我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。
使用的技术:
Spring Boot 1.4.2.RELEASE、Spring 4.3.4.RELEASE、Thymeleaf 2.1.5.RELEASE、Tomcat 嵌入 8.5.6、Maven 3、Java 8
我有这个测试,但失败了,因为 Junit 测试没有回滚插入 java.lang.AssertionError: expected:<1> but was:<2>
@ContextConfiguration(classes={PersistenceConfig.class})
@RunWith(SpringRunner.class)
public class JdbcGuardianRepositoryTests {
@Autowired
private JdbcGuardianRepository repository;
@Test
public void testGetAllGuardians() throws DataAccessException, SQLException {
assertEquals(1, repository.getAllGuardians(null).size());
}
@Test
@Rollback
public void testInsetGuardian() throws DataAccessException, SQLException {
Guardian newGuardian = new Guardian();
newGuardian.setDescription("bob desc");
newGuardian.setEmail("bob@gmail.com");
newGuardian.setId(Sequencer.getNextVal());
newGuardian.setMobile("123456789");
newGuardian.setName("bob");
newGuardian.setSurName("bob surname");
assertNotEquals(-1, repository.insert(newGuardian));
}
}
【问题讨论】:
-
它究竟是如何“失败”的?
标签: java spring spring-boot junit4 h2