Struts2.3.12 junit4 testcase request & session are null

前端 未结 3 1065
小蘑菇
小蘑菇 2020-12-20 02:30

I have already gone through this solution : Struts 2 JUnit Plugin v2.2.3: Test Class Extending StrutsTestCase; 'request' is null

But I\'m already not having

相关标签:
3条回答
  • 2020-12-20 02:57

    To avoid request from being null:

    request = new MockHttpServletRequest();
    

    For session:

    Map<String, Object> sessionMap = new HashMap<String, Object>();
    actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);
    
    0 讨论(0)
  • 2020-12-20 03:02

    If you are using getActionProxy method to execute your actions then you need to set new session map into the invocation context.

    ActionProxy actionProxy = getActionProxy("/action");
    Map<String, Object> sessionMap = new HashMap<String, Object>();
    actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);
    actionProxy.execute();
    

    If you don't need reference to action proxy then you can use executeAction method. Note that executeAction will return actual output of the result, not the result returned from execute method.

    0 讨论(0)
  • 2020-12-20 03:03

    In my case I needed to call super.setUp from my test.

    0 讨论(0)
提交回复
热议问题