测试积点老人 发表于 2021-11-23 13:16:57

用test方法测试serviceImpl层时空指针异常

利用test方法测试,出现空指针异常,而且swagger文档显示no response from server

public List<Test> queryProjectOrg(Integer userId) {
      String role = projectInfoDao.queryRoleByUser(userId);
      List<Test> list = new ArrayList<Test>();
      if ("ALL".equals(role)){
            list = projectInfoDao.findAllOrg();
      }else {
            list = projectInfoDao.queryOrg(userId);
      }
      return list;
    }List<Test> findAllOrg();
    List<Test> queryOrg(@Param("userId")Integer userId);

    String queryRoleByUser(@Param("userId") Integer userId);

List<Test> findAllOrg();
    List<Test> queryOrg(@Param("userId")Integer userId);

    String queryRoleByUser(@Param("userId") Integer userId);
}运行结果及报错内容
java.lang.NullPointerException
at com.enn.service.impl.ProjectInfoServiceImpl.queryProjectOrg(ProjectInfoServiceImpl.java:242)
at com.frame.test1.find(test1.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)这个应该怎么解决呢

海海豚 发表于 2021-11-24 09:36:16

https://blog.csdn.net/weixin_47389462/article/details/108286811   参考下看看

qqq911 发表于 2021-11-24 11:36:55

看下应用日志,那个地方报错
页: [1]
查看完整版本: 用test方法测试serviceImpl层时空指针异常