【发布时间】:2019-09-01 19:59:20
【问题描述】:
我在运行 Junit 测试时遇到问题,我有错误:
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
at org.springframework.util.Assert.state(Assert.java:73)
我怎么看,Spring Boot 找不到我的测试类。我有多个 Maven 模块,在我的 A 模块中我有 SpringBootApplication 类和控制器,在模块 B 我有我的服务模块,我写了我的测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestClass{
@Autowired
private ImplDatabase serviceDatabase;
@MockBean
private Repository repository;
@Test
public void saveMethode() {
Model model= new Model ();
event.setCreated(LocalDateTime.now());
model.setMessage("sdsd");
model.setCategory("Somi");
when(repository.save(model)).thenReturn(model);
assertEquals(model, serviceDatabase.saveTest(model));
}
}
我有C 模块,其中存储了我的Repository。
依赖的层次是:我在A 模块中对B 和C 有依赖,在B 模块中我对C 有依赖。
【问题讨论】:
标签: java maven spring-boot mockito junit4