Jfinal 怎么对service层做单元测试呢,
看到这篇文章介绍了对congtroller做单元测试 那对sevice层怎么做单元测试呢
我再junit 里面写sql查询汇报这样的空指针异常
AssignSeller.testAssignSeller (Failed Tests first)
testAssignSeller(com.canyou.AssignSeller)
java.lang.NullPointerException
at com.jfinal.plugin.activerecord.Model.find(Model.java:567)
at com.jfinal.plugin.activerecord.Model.findFirst(Model.java:594)
at com.jfinal.plugin.activerecord.Model.findFirst(Model.java:603)
at com.canyou.AssignSeller.getClient(AssignSeller.java:29)
at com.canyou.AssignSeller.testAssignSeller(AssignSeller.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
switch (sourceType) {
case 0:// 传值
break;
case 1:// 个人邀请
// 随机邀请人
Clientbase iClient = Clientbase.dao
.findFirst("select * from crm_clientbase_tb order by rand() LIMIT 1");
client.setSourceType(1);
client.setInvitationCode(String.valueOf(iClient.getId()));
break;
case 2:
Activity act = Activity.dao.findFirst("select * from mkt_activity_tb order by rand() LIMIT 1");
client.setSourceType(2);
client.setInvitationCode(String.valueOf(act.getId()));
break;
case 4:
Organization org = Organization.dao
.findFirst("select * from crm_organization_tb order by rand() LIMIT 1");
client.setSourceType(4);
client.setInvitationCode(String.valueOf(org.getId()));
break;
default:
break;
}
return client;
写 这样的代码 测试会报空指针异常
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢
在 jfinal 官网下载 jfinal 手册,看一下《5.13 任意环境下使用 ActiveRecord》这一章节,里面介绍了如何在任意环境下使用 active record plugin