[英]Adding JAR files to your testing classpath:
Am performing a junit test on one of my methods in a class in android. 我正在对android中的一个类中的一个方法执行junit测试。 and according to the info at http://code.google.com/appengine/docs/java/tools/localunittesting.html i should add the libraries below to my classpath. 并根据http://code.google.com/appengine/docs/java/tools/localunittesting.html上的信息,我应该将下面的库添加到我的类路径中。
${SDK_ROOT}/lib/impl/appengine-api.jar
${SDK_ROOT}/lib/impl/appengine-api-labs.jar
${SDK_ROOT}/lib/impl/appengine-api-stubs.jar
My question is, where in us should i get this libraries and how should i add them? 我的问题是,我应该在哪里获得这个库,我应该如何添加它们? am using android studio running on ubuntu 15 64bit. 我正在使用在ubuntu 15 64bit上运行的android studio。
am fairly new in android and GAE things! 我是android和GAE的新手!
what i have tried this is what i have added to my modlue's build.gradle 我试过的是我添加到modlue的build.gradle中的内容
dependencies {
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
testCompile 'com.google.appengine:appengine-testing:1.8.2'
testCompile 'com.google.appengine:appengine-api-labs:1.8.2'
testCompile 'com.google.appengine:appengine-api-stubs:1.8.2'
testCompile 'com.google.appengine:appengine-tools-sdk:1.8.2'
testCompile 'org.json:json:20141113'
}
When i try to run my junit test class. 当我尝试运行我的junit测试类。 this is what am getting 这就是我要得到的
com.googlecode.objectify.SaveException: Error saving
com.top.ash.backend.entities.Ameggedon@589b3632: No API environment is registered for this thread.
com.googlecode.objectify.impl.EntityMetadata.save(EntityMetadata.java:95)
at com.googlecode.objectify.impl.WriteEngine.save(WriteEngine.java:75)
at com.googlecode.objectify.impl.SaverImpl.entities(SaverImpl.java:60)
at com.googlecode.objectify.impl.SaverImpl.entity(SaverImpl.java:35)
org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.NullPointerException: No API environment is registered for this thread.
Note: I know nothing about GAE, but here is how you can add jars from folder to test classpath. 注意: 我对GAE一无所知,但是这里是如何从文件夹添加jar到测试类路径的。
Create a new folder in the same directory as libs
folder (in this picture it is called testlibs
). 在与libs
文件夹相同的目录中创建一个新文件夹(在此图中称为testlibs
)。 In this directory you should put those jars. 在这个目录中你应该放这些罐子。
Now, add to the build.gradle
of the module (not of the project), inside dependencies
block: 现在,添加到模块(而不是项目)的build.gradle
中,在dependencies
块内:
dependencies {
...
testCompile fileTree(dir: 'testlibs', include: ['*.jar'])
}
Now in your tests (Junit, not instrumentation) you could use the methods from the jar. 现在在你的测试中(Junit,而不是仪器)你可以使用jar中的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.