如何在会话对象中使用JMockit setAttribute进行测试?

时间:2014-10-21 02:50:17

标签: java testing junit jmockit

我有以下问题,我尝试过使用JMockit进行测试,一切正常,直到我测试以下行:

request.getSession().setAttribute("property", new Object ()); 

告诉我问题如下:

  
    

mockit.internal.UnexpectedInvocation:javax.servlet.http.HttpSession的参数1#setAttribute(String,Object)java.lang.Object@1d10f4e expect,java.lang.Object@69e70e6c     在pac.con.servlets.Transfer.defaultAction(transfer.java:69)     at pac.con.servlets.transfer.TransferTests.testTransfer(TransferTests.java:110)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     在java.lang.reflect.Method.invoke(Method.java:606)     在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)     在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)     在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

  

在我的测试中,我尝试按如下方式设置该对象:

request.getSession (); returns (session); 
session.setAttribute ("property", new Object ()); 

问候和感谢

0 个答案:

没有答案