簡體   English   中英

將JAR文件添加到測試類路徑:

[英]Adding JAR files to your testing classpath:

我正在對android中的一個類中的一個方法執行junit測試。 並根據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

我的問題是,我應該在哪里獲得這個庫,我應該如何添加它們? 我正在使用在ubuntu 15 64bit上運行的android studio。

我是android和GAE的新手!

我試過的是我添加到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'
}

當我嘗試運行我的junit測試類。 這就是我要得到的

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.

注意: 我對GAE一無所知,但是這里是如何從文件夾添加jar到測試類路徑的。

在與libs文件夾相同的目錄中創建一個新文件夾(在此圖中稱為testlibs )。 在這個目錄中你應該放這些罐子。

夾

現在,添加到模塊(而不是項目)的build.gradle中,在dependencies塊內:

dependencies {
    ...
    testCompile fileTree(dir: 'testlibs', include: ['*.jar'])
}

現在在你的測試中(Junit,而不是儀器)你可以使用jar中的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM