在跟着it黑马学习mybatis的时候,有一个代码测试插数据,一直报错,我的junit是4.12版本。代码如下:
@Test
public void addUser() throws Exception {
User user = new User();
user.setUid(7);
user.setUname("jhon");
user.setUage(30);
userMapper.addUser(user);
sqlSession.commit();
sqlSession.close();
}
报错如下:
java.lang.Exception: No tests found matching Method addUser(com.itheima.mapper.UserMapperTest) from org.junit.internal.requests.ClassRequest@b1bc7ed
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Process finished with exit code -1
解决办法:
将addUser()更换为testAddUser()就可以了。
@Test注解在进行测试时,需要要求函数名称以“test”开头。