【发布时间】:2017-08-17 08:34:14
【问题描述】:
我正在尝试运行一个简单的 Junit 测试以查看我的 JpaRepository 是否确实在工作。
我不断收到的错误是:
Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test java.lang.IllegalStateException doesn't spring boot configure itself?
我的测试班:
@RunWith(SpringRunner.class)
@DataJpaTest
public class LogConnectionTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private LogConnectionDao logConnectionDao;
@Test
public void ajouterTest() throws Exception{
this.entityManager.persist(new LogConnection("Test",4));
LogConnection logConnection = this.logConnectionDao.findOne((long)1);
assertThat(logConnection.getClasseName().equals("Test"));
assertThat(logConnection.getOriginalId() != 5);
}
}
我的 Spring 启动应用程序:
@SpringBootApplication
public class UpsysmarocLibraryLogApplication {
public static void main(String[] args) {
SpringApplication.run(UpsysmarocLibraryLogApplication.class, args);
}
}
我的仓库:
public interface LogConnectionDao extends JpaRepository<LogConnection,Long> {
}
【问题讨论】:
-
你需要在你的
LogConnectionTest类上使用SpringBootTest注解
标签: java spring spring-boot spring-data-jpa