我是机器人领域的新手,并使用本教程开始学习
https://android.jlelse.eu/robolectric-unit-testing-framework-for-android-b78ebac0b411。
我正在使用此JDK
JAVA_HOME = C:\ Program Files \ Java \ jdk-11.0.1
然而,无论什么(:
任何想法我该如何解决?
这是gradle:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.guitarv.robotest"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation "org.robolectric:robolectric:3.3.2"
}
这是样本中什么都不做的单元测试的一部分:
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP_MR1)
@RunWith(RobolectricTestRunner.class)
public class MainActivityTest {
private Activity activity;
// 3
@Before
public void setup() {
//activity = Robolectric.buildActivity(MainActivity.class).create().get();
}
@Test // 4
public void validateTextViewContent() {
//TextView textView = (TextView) activity.findViewById(R.id.text_view);
// 5
//assertNotNull("TextView is null", textView);
// 6
//assertTrue("TextView's text does not match.", "Hello Robolectric!".equals(textView.getText().toString()));
}
}
我故意注释掉了所有代码,但仍然不断得到:
"C:\Program Files\Android\Android Studio\jre\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 -Didea.launcher.port=61050 "-Didea.launcher.bin.path=C:\Program Files\Android\Android Studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Android\Android Studio\lib\idea_rt.jar;C:\Program Files\Android\Android Studio\plugins\junit\lib\junit-rt.jar;C:\Program Files\Android\Android Studio\plugins\junit\lib\junit5-rt.jar;C:\Users\goliveira\AppData\Local\Android\Sdk\platforms\android-28\data\res;D:\gmmo\accriva\dev\misc\droid\RoboEletricTest\app\build\intermediates\javac\debugUnitTest\compileDebugUnitTestJavaWithJavac\classes;D:\gmmo\accriva\dev\misc\droid\RoboEletricTest\app\build\intermediates\javac\debug\compileDebugJavaWithJavac\classes;D:\gmmo\accriva\dev\misc\droid\RoboEletricTest\app\build\generated\res\rs\debug;D:\gmmo\accriva\dev\misc\droid\RoboEletricTest\app\build\generated\res\resValues\debug;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\backport-util-concurrent\backport-util-concurrent\3.1\682f7ac17fed79e92f8e87d8455192b63376347b\backport-util-concurrent-3.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\localbroadcastmanager-28.0.0.aar\b3c58c4eb60e9210b5d76238a783884e\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\support-vector-drawable-28.0.0.aar\371b6522d664fc5b787ee41c99f0347c\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\interpolator-28.0.0.aar\a18477ce77c1bc73879414a4c1189ef5\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\support-core-utils-28.0.0.aar\d48404db6dbf03f1f6d60821baa8627b\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-error-diagnostics\2.2.1\e81bb342d7d172f23d108dc8fa979a1facdcde8e\maven-error-diagnostics-2.2.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\drawerlayout-28.0.0.aar\e637c84c580b131b2350f433bda154ae\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\coordinatorlayout-28.0.0.aar\7c08ed52390afce91866a0f172731525\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\coordinatorlayout-28.0.0.aar\7c08ed52390afce91866a0f172731525\res;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven.wagon\wagon-http-lightweight\1.0-beta-6\b3815078570c3b1f0667e123d59717c6b726c6c2\wagon-http-lightweight-1.0-beta-6.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-project\2.2.1\8239e98c16f641d55a4ad0e0bab0aee3aff8933f\maven-project-2.2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven.wagon\wagon-file\1.0-beta-6\6c53633505460caf49d2660de1e24744d915afb9\wagon-file-1.0-beta-6.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven.wagon\wagon-provider-api\1.0-beta-6\3f952e0282ae77ae59851d96bb18015e520b6208\wagon-provider-api-1.0-beta-6.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.3.aar\1bcfd614af80c4832f67420ed3c169cb\res;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\constraint-layout-1.1.3.aar\1bcfd614af80c4832f67420ed3c169cb\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\swiperefreshlayout-28.0.0.aar\5f33f72b473c63a42f22a2684c667af0\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.ant\ant\1.8.0\7b456ca6b93900f96e58cc8371f03d90a9c1c8d1\ant-1.8.0.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\xpp3\xpp3_min\1.1.4c\19d4e90b43059058f6e056f794f0ea4030d60b86\xpp3_min-1.1.4c.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\livedata-1.1.1.aar\955c5f3ce9a18760008044450d2bd7ac\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.bouncycastle\bcprov-jdk16\1.46\ce091790943599535cbb4de8ede84535b0c1260c\bcprov-jdk16-1.46.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric\3.3.2\90022fc9ad52c44d0c2a13b8371e9a3624357ba8\robolectric-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\shadow-api\3.3.2\b27c499e077a842330aca3f76615af8bff0fab29\shadow-api-3.3.2.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\versionedparcelable-28.0.0.aar\c720aed29e0f6ad3ffce1a8fdf53b870\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\runtime-1.1.1.aar\31cdc70d8f0bdb1d27d07983a12ad3e2\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\20.0\89507701249388e1ed5ddcf8c41f4ce1be7831ef\guava-20.0.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\loader-28.0.0.aar\a2c1dc655b8a52ced6a718a8e802779b\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\viewpager-28.0.0.aar\06c54ff569e312ccfa71e4fcdc7985ca\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric-sandbox\3.3.2\4d968978679b572e5993b3eea35cae88268f44ee\robolectric-sandbox-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.android.support\support-annotations\28.0.0\ed73f5337a002d1fd24339d5fb08c2c9d9ca60d8\support-annotations-28.0.0.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\shadows-core\3.3.2\3d20e0784abd5d6ccf58eeb82da908ecbf7bffd9\shadows-core-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.almworks.sqlite4java\sqlite4java\0.282\745a7e2f35fdbe6336922e0d492c979dbbfa74fb\sqlite4java-0.282.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-artifact-manager\2.2.1\ec355b913c34d37080810f98e3f51abecbe1572b\maven-artifact-manager-2.2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-settings\2.2.1\2236ffe71fa5f78ce42b0f5fc22c54ed45f14294\maven-settings-2.2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.android.support.constraint\constraint-layout-solver\1.1.3\bde0667d7414c16ed62d3cfe993cff7f9d732373\constraint-layout-solver-1.1.3.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\runtime-1.1.1.aar\592b1351298476a94ec1712db1b91201\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.codehaus.plexus\plexus-container-default\1.0-alpha-9-stable-1\94aea3010e250a334d9dab7f591114cd6c767458\plexus-container-default-1.0-alpha-9-stable-1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\customview-28.0.0.aar\7955ec8523e8028326883f2e231f469a\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.thoughtworks.xstream\xstream\1.4.8\520d90f30f36a0d6ba2dc929d980831631ad6a92\xstream-1.4.8.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm\5.0.1\2fd56467a018aafe6ec6a73ccba520be4a7e1565\asm-5.0.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-plugin-registry\2.2.1\72a24b7775649af78f3986b5aa7eb354b9674cfd\maven-plugin-registry-2.2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm-tree\5.0.1\1b1e6e9d869acd704056d0a4223071a511c619e6\asm-tree-5.0.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\support-core-ui-28.0.0.aar\642f5b61e8611ac9fd4b75bfb9725126\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-ant-tasks\2.1.3\b09be554228d66d208e5fef5266844aacf443abc\maven-ant-tasks-2.1.3.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\slidingpanelayout-28.0.0.aar\f90b7075c9c10d61058f4dbaeac8f2f6\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.ibm.icu\icu4j\53.1\786d9055d4ca8c1aab4a7d4ac8283f973fd7e41f\icu4j-53.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\viewmodel-1.1.1.aar\3f70ea745461b173c85d6688df0a45d5\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.google.protobuf\protobuf-java\2.6.1\d9521f2aecb909835746b7a5facf612af5e890e8\protobuf-java-2.6.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric-junit\3.3.2\fd1cb1d27d125c0826feddfcd00653f2f16e458d\robolectric-junit-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.android.support\collections\28.0.0\c1bcdade4d3cc2836130424a3f3e4182c666a745\collections-28.0.0.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven.wagon\wagon-http-shared\1.0-beta-6\ccd70d7e0d8c085e648a83f072da06ca9a53be94\wagon-http-shared-1.0-beta-6.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\documentfile-28.0.0.aar\ecb51ab8a338322fd5ee210413d745be\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.ant\ant-launcher\1.8.0\8b53ba16fa62fb1034da8f1de200ddc407c8381\ant-launcher-1.8.0.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm-commons\5.0.1\7b7147a390a93a14d2edfdcf3f7b0e87a0939c3e\asm-commons-5.0.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-profile\2.2.1\3950071587027e5086e9c395574a60650c432738\maven-profile-2.2.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\cursoradapter-28.0.0.aar\3bd07da01bf98a85596dec6dc27cc586\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\nekohtml\nekohtml\1.9.6.2\2d960be7b62ae6622dbbbe49ab4ffdc609f85c80\nekohtml-1.9.6.2.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\asynclayoutinflater-28.0.0.aar\7e74ec87a85890a1f51ca394d667bf88\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\nekohtml\xercesMinimal\1.9.6.2\d1c5e063683a0e6f77cd5f051a9d4af48346fa6\xercesMinimal-1.9.6.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-model\2.2.1\c0a1c17436ec3ff5a56207c031d82277b4250a29\maven-model-2.2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric-utils\3.3.2\c94200e8e1176caa63ff46ff6f2870990f5642cc\robolectric-utils-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\android.arch.core\common\1.1.1\e55b70d1f5620db124b3e85a7f4bdc7bd48d9f95\common-1.1.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.assertj\assertj-core\2.6.0\b532c3fc4f66bcfee4989a3514f1cd56203a33ad\assertj-core-2.6.0.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-repository-metadata\2.2.1\98f0c07fcf1eeb213bef8d9316a9935184084b06\maven-repository-metadata-2.2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\print-28.0.0.aar\17c6a6e80e92037579f91880318e5f28\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric-resources\3.3.2\b1a0ccac05e19a5fa2b21d462375c7603e2203b\robolectric-resources-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\com.google.android.apps.common.testing.accessibility.framework\accessibility-test-framework\2.1\c2d6267c3ad0435ddf9e27a94a0e0af4ca3fdfbb\accessibility-test-framework-2.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-library\1.3\4785a3c21320980282f9f33d0d1264a69040538f\hamcrest-library-1.3.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\support-fragment-28.0.0.aar\b0e409047e22879ce4f39cadf04c923f\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\android.arch.lifecycle\common\1.1.1\207a6efae6a3555e326de41f76bdadd9a239cbce\common-1.1.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\livedata-core-1.1.1.aar\d56bc7861e06858b588fafb8395f6375\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\3aa2d1093d375e1c9c74fa3858a94797\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\3aa2d1093d375e1c9c74fa3858a94797\res;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.codehaus.plexus\plexus-interpolation\1.11\ad9dddff6043194904ad1d2c00ff1d003c3915f7\plexus-interpolation-1.11.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.codehaus.plexus\plexus-utils\1.5.15\c689598ce1eb94c304817877ed15911099972526\plexus-utils-1.5.15.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-28.0.0.aar\9f7504f5407395a5f670b89c9c4ab36b\jars\classes.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.apache.maven\maven-artifact\2.2.1\23600f790d4dab2cb965419eaa982e3e84c428f8\maven-artifact-2.2.1.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\339a1fc7f52a5d15a2ebd061be344fc7\jars\classes.jar;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0.aar\339a1fc7f52a5d15a2ebd061be344fc7\res;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\xmlpull\xmlpull\1.1.3.1\2b8e230d2ab644e4ecaa94db7cdedbc40c805dfa\xmlpull-1.1.3.1.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric-annotations\3.3.2\9aabda1b5c03c0077e0224058a444c23bc1162ac\robolectric-annotations-3.3.2.jar;C:\Users\goliveira\.gradle\caches\modules-2\files-2.1\classworlds\classworlds\1.1-alpha-2\5adf2e681c57d7f48038b602f3ca2254ee82d47\classworlds-1.1-alpha-2.jar;D:\gmmo\accriva\dev\misc\droid\RoboEletricTest\app\build\intermediates\sourceFolderJavaResources\test\debug;D:\gmmo\accriva\dev\misc\droid\RoboEletricTest\app\build\intermediates\sourceFolderJavaResources\debug;C:\Users\goliveira\.gradle\caches\transforms-1\files-1.1\android.jar\50278f1e57ccc2849b9cf0e83a034629\android.jar" com.intellij.rt.execution.application.AppMainV2 com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.guitarv.robotest.MainActivityTest
No such manifest file: build\intermediates\bundles\debug\AndroidManifest.xml
java.lang.RuntimeException: java.lang.NullPointerException
at org.robolectric.res.ResourceTableFactory.parseResourceFiles(ResourceTableFactory.java:155)
at org.robolectric.res.ResourceTableFactory.newResourceTable(ResourceTableFactory.java:43)
at org.robolectric.res.ResourceMerger.buildResourceTable(ResourceMerger.java:22)
at org.robolectric.RobolectricTestRunner.getAppResourceTable(RobolectricTestRunner.java:450)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:288)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:203)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
... a bunch of stuff here that I removed
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.NullPointerException
at org.robolectric.res.DocumentLoader.loadFile(DocumentLoader.java:35)
at org.robolectric.res.DocumentLoader.load(DocumentLoader.java:26)
at org.robolectric.res.ResourceTableFactory.parseResourceFiles(ResourceTableFactory.java:140)
... 24 more
以及我的运行方式(右键单击MainActivityTest):
最后文件的位置: