自己写了个类TestA继承自AbstractMvcTest,测试时报java.lang.NullPointerException
at org.nutz.mock.AbstractMvcTest.before(AbstractMvcTest.java:46)
@IocBean
@InjectName
public class TestA extends AbstractMvcTest{
@Override
protected void initServletConfig() {
servletConfig.addInitParameter("modules", "cn.guagua.mobile.MainModule");
}
@org.junit.Test
public void test(){
request.setPathInfo("/user/login");
request.addParameter("userid", "1");
request.addParameter("password", "10");
try {
servlet.service(request, response);
System.out.println(response.getAsString());
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
出错信息
java.lang.NullPointerException
at org.nutz.mock.AbstractMvcTest.before(AbstractMvcTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
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.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)
出错的源代码 nc = Mvcs.getNutConfig();这一行nc是空的
@Override
@Before
public void before() throws Exception {
servletContext = Mock.servlet.context();
servletConfig = new MockServletConfig(servletContext, "nutz");
initServletConfig();
servlet = new NutServlet();
servlet.init(servletConfig);
session = Mock.servlet.session(servletContext);
newreq();
nc = Mvcs.getNutConfig();
ioc = nc.getIoc();
injectSelfFields();
_before();
}