在使用springboot测试类时如果不注意就会出现这个异常
这是因为Junit4要求测试的方法为public
且返回值为void
例如这样:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MybatisPlusTest {
@Autowired
private UserMapper userMapper;
@Test
void contextLoads() {
List<User> users = userMapper.selectList(null);
users.forEach(System.out::println);
}
}
在运行时就会出现这个异常
要解决这个问题,只需要给被测试的方法添加Public
就行了
@Test
public void contextLoads() {
List<User> users = userMapper.selectList(null);
users.forEach(System.out::println);
}