我对 Spring 测试比较陌生。我正在尝试测试存储库。
在阅读了有关同一问题的不同帖子后,这似乎是一个依赖问题。但我检查后没有发现任何冲突(见下文)。
这是测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ActionRepositoryTest2 {
@Autowired ActionRepository actionRepository;
@Test
public void actionRepository() {
Command command = new Command();
Action action = new Action();
action.setText("TestAction");
actionRepository.save(action);
List<Action> actions = (List<Action>)
actionRepository.findAll();
assertNotNull(action);
assertEquals(actions.size(),1);
}
@Configuration
public static class InnerConf2 {
@Bean
ActionRepository actionRepository() {
return new ActionRepositoryImpl();
}
@Bean
CommandRepository commandRepository() {
return new CommandRepositoryImpl();
}
@Bean
OrderRepository orderRepository() {
return new OrderRepositoryImpl();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的异常:
ava.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's …Run Code Online (Sandbox Code Playgroud)