2015-09-14 132 views
1

我正在對android中類中的某個方法執行junit測試。根據http://code.google.com/appengine/docs/java/tools/localunittesting.html的信息,我應該將下面的庫添加到我的類路徑中。將JAR文件添加到您的測試類路徑中:

${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 
[email protected]: 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. 

回答

1

注:我一無所知GAE,但在這裏是如何從文件夾添加罐測試類路徑中。

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

Folder

,添加到模塊(而不是項目)的build.gradle,裏面dependencies塊:

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

現在(JUnit中,未實現的),你可以使用來自jar的方法。

+0

如何在同步我的項目後下載這些.jar文件?他們在哪個文件夾中存儲? –

+0

http://stackoverflow.com/questions/5405211/initialize-local-datastore-exception-no-api-environment-is-registered-for-this –

+0

如何添加這些.jar文件。我是通過將它們包含在模塊的gradle文件中來做正確的方式嗎?因爲它來自正在創建測試課程的這個模塊。 –

相關問題