51Testing软件测试论坛

标题: 用test方法测试serviceImpl层时空指针异常 [打印本页]

作者: 测试积点老人    时间: 2021-11-23 13:16
标题: 用test方法测试serviceImpl层时空指针异常
利用test方法测试,出现空指针异常,而且swagger文档显示no response from server

  1. public List<Test> queryProjectOrg(Integer userId) {
  2.         String role = projectInfoDao.queryRoleByUser(userId);
  3.         List<Test> list = new ArrayList<Test>();
  4.         if ("ALL".equals(role)){
  5.             list = projectInfoDao.findAllOrg();
  6.         }else {
  7.             list = projectInfoDao.queryOrg(userId);
  8.         }
  9.         return list;
  10.     }
复制代码
  1. List<Test> findAllOrg();
  2.     List<Test> queryOrg(@Param("userId")Integer userId);

  3.     String queryRoleByUser(@Param("userId") Integer userId);
复制代码

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

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

作者: 海海豚    时间: 2021-11-24 09:36
https://blog.csdn.net/weixin_47389462/article/details/108286811   参考下看看
作者: qqq911    时间: 2021-11-24 11:36
看下应用日志,那个地方报错




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2