gae(google app engine for java) 单元测试 Junit 怎么抛空指针

zzzcrpp 2009-10-04
我用GAE SDK 1.2.5 版本,做 Junit 测试总是报空指针错误,在网上查看了别人写的代码,也测试了GAE 自带的例子,但在我的本地互环境就测试不通,抛空指针错误,不知道有有没有遇到类似的问题,可以分享/探讨一下.QQ:88447074 MSN: zzzcrpp@msn.com

谢谢!

java.lang.NullPointerException
at com.google.appengine.api.NamespaceManager.get(NamespaceManager.java:98)
at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace(DatastoreApiHelper.java:81)
at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace(DatastoreApiHelper.java:73)
at com.google.appengine.api.datastore.Key.<init>(Key.java:100)
at com.google.appengine.api.datastore.Key.<init>(Key.java:85)
at com.google.appengine.api.datastore.Key.<init>(Key.java:81)
at com.google.appengine.api.datastore.Entity.<init>(Entity.java:103)
at com.google.appengine.api.datastore.Entity.<init>(Entity.java:84)
at org.datanucleus.store.appengine.DatastoreFieldManager.<init>(DatastoreFieldManager.java:167)
at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPreProcess(DatastorePersistenceHandler.java:316)
at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects(DatastorePersistenceHandler.java:236)
at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:225)
at org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent(JDOStateManagerImpl.java:3185)
at org.datanucleus.state.JDOStateManagerImpl.makePersistent(JDOStateManagerImpl.java:3161)
at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1298)
at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1175)
at org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:669)
at org.datanucleus.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:694)
at com.yoolive.dao.UserDaoImpl.addUser(UserDaoImpl.java:23)
at com.yoolive.dao.UserDaoTest.testAddUsers(UserDaoTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

wendal 2009-10-16
我只有知道, 在GAE上用Junit 4.7的话,需要重写BaseTestRunner, 避免加载$/user.home/junit.proproints文件. 起码我是这样做的.

[url]
http://wendalx999.appspot.com/check?class=org.nutz.castor.CastorTest
[/url]

这是一个示例,使用修改过的BaseTestRunner


你的情况,我就没见过.
weiqiang.yang 2009-11-09
我也想问这个问题,不知道怎么测试service
weiqiang.yang 2009-11-09
@wendal
你给的链接点击满屏幕的异常。。。
wendal 2009-11-10
异常, 总共才2个. 那两个测试想直接读文件.

其他一切正常.
sylinx_yqg 2009-12-30
TestEnvironment中的
public String getRequestNamespace()
public String getDefaultNamespace()

不返回空试试
skzr.org 2010-01-16
这样配置即可
new ApiProxyLocalImpl(new File("./war"/**不是例子中的"."*/)){};
hj-xy 2010-01-25
给你的ApiProxy.Environment的实现类中的public Map<String, Object> getAttributes()方法返回一个new HashMap<String, Object>()。
Global site tag (gtag.js) - Google Analytics