基础配置以及常见错误
目前版本的Android Studio 3.6.3/4.0/4.1/4.2使用Robolectric-3.8/4.3.1/4.5.1/4.6.1,只能配合Powermock-1.6.6,不能高于这个版本PowerMock ,尽管软件源中的版本已经更新升级到2.0.7版本了,但是Robolectric并没有及时更新依赖。尝试过使用最新版本的PowerMock,结果很多莫名的报错。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// 单元测试 testImplementation "com.android.support.test:runner:1.0.2" testImplementation "junit:junit:4.13.2" testImplementation "org.robolectric:robolectric:4.5.1" // 注意AndroidX环境下,不能引入shadows-supportv4,Jetifier转换的时候报错 testImplementation "org.robolectric:shadows-supportv4:4.5.1" // MultiDex支持 testImplementation "org.robolectric:shadows-multidex:4.5.1" // 此处版本更新需要特别小心,目前 robolectric 跟 powermock 存在兼容问题, // 需要固定的某些版本才能正常配合 // 依赖关系参考 // https://github.com/robolectric/robolectric/wiki/Using-PowerMock testImplementation "org.powermock:powermock-module-junit4:1.6.6" testImplementation "org.powermock:powermock-module-junit4-rule:1.6.6" testImplementation "org.powermock:powermock-classloading-xstream:1.6.6" testImplementation "org.powermock:powermock-api-mockito:1.6.6" |
如果 Windows 系统下出现如下提示,受限于Windows系统路径不能超过260个字符的限制
1 |
13:36 Error running 'xxxTest': Command line is too long. Shorten command line for xxxTest or also for Android JUnit default configuration. |
貌似Windows 10 Build 14352版中已经可以通过修改注册表去除260字符的路径长度限制了。
在项目/.idea/workspace.xml
文件中添加一行代码如下
1 2 3 4 |
<component name="PropertiesComponent"> ... <property name="dynamic.classpath" value="true" /> </component> |
对于使用MultiDex的应用,如果报告如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
java.lang.RuntimeException: MultiDex installation failed (/var/folders/h6/4__l0pyn32j1mkkysynnxydr0000gn/T/robolectric-Method_xxxxxxxxxxxx_isCorrect4035485067136008322/com.xxxx.xxxx.app-sourceDir (Is a directory)). at android.support.multidex.MultiDex.install(MultiDex.java:121) at com.xxx.xx.app.xx.application.xxxxxx.attachBaseContext(MyApplication.java:212) at android.app.Application.attach(Application.java:212) at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:283) at org.robolectric.shadows.ShadowApplication.callAttach(ShadowApplication.java:79) at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:250) at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:169) at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:301) at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:243) at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) |
需要在build.gradle
中引入
1 2 3 |
// MultiDex支持 testImplementation "org.robolectric:shadows-multidex:4.5.1" |
例子测试代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package com.mobibrw.example; import org.junit.Test; import static org.junit.Assert.*; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadows.multidex.ShadowMultiDex; /** * Example local unit test, which will execute on the development machine (host). * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ @RunWith(RobolectricTestRunner.class) @PowerMockIgnore("jdk.internal.reflect.*") @Config(shadows = ShadowMultiDex.class) public class ExampleUnitTest { @Test public void addition_isCorrect() { assertEquals(4, 2 + 2); } } |
注意,需要
1 |
@Config(shadows = ShadowMultiDex.class) |
才能使得配置生效。
如果发生如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
java.lang.VerifyError: Expecting a stackmap frame at branch target 43 Exception Details: Location: com/meizu/cloud/pushsdk/base/IntentReceiver.onReceive(Landroid/content/Context;Landroid/content/Intent;)V @6: ifne Reason: Expected stackmap frame at this location. Bytecode: 0x0000000: b200 08b6 0013 9a00 25bb 0004 5912 0110 0x0000010: 0ab7 000e 59b3 000a b600 10bb 0003 59b2 0x0000020: 000a b600 0fb7 000c b300 09b2 0009 bb00 0x0000030: 0659 2a2b 2cb7 0011 b600 0d57 b1 at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at java.lang.Class.getConstructor0(Class.java:3075) at java.lang.Class.getDeclaredConstructor(Class.java:2178) at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:396) at org.robolectric.internal.bytecode.ShadowImpl.newInstanceOf(ShadowImpl.java:18) at org.robolectric.shadow.api.Shadow.newInstanceOf(Shadow.java:35) at org.robolectric.android.internal.AndroidTestEnvironment.registerBroadcastReceivers(AndroidTestEnvironment.java:541) at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:265) at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:169) at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:301) at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:243) at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) |
JDK 1.7引入了代码校验,这个我们需要关闭这个功能才行,如下图:
可惜的是, 目前如果需要在Android Studio
中运行或者测试单个测试用例,需要每个测试文件单独添加才行。
对于使用
1 |
$ bash gradlew test |
运行测试的情况来说,需要在项目app/build.gradle
下添加如下内容:
1 2 3 4 5 6 7 |
android { ............................... testOptions { unitTests.all { jvmArgs '-noverify' } } ............................... } |
也可以添加到defaultConfig
下面,如下:
1 2 3 4 5 6 7 8 9 10 11 |
android { ............................... defaultConfig { ..................... testOptions { unitTests.all { jvmArgs '-noverify' } } ..................... } ............................... } |
这个问题更详细的解释如下:
1 2 3 4 5 6 7 8 9 |
Java 7引入了更严格的验证,并稍微改变了类格式 - 以包含用于验证代码是否正确的堆栈映射。您看到的异常意味着某些方法没有有效的堆栈映射。 Java版本或字节码工具都可能是责任。通常这意味着应用程序使用的库生成的节码不能通过更严格的验证。因此,可以将其作为一个错误报告给库的开发者。 作为解决方法,您可以添加-noverify到JVM参数以禁用验证。 在Java 7中,还可以通过添加 -XX:-UseSplitVerifier 使用较不严格的验证方法,但在Java 8中删除了该选项(-XX:-UseSplitVerifier)。 很大的可能是第三方库是低版本的JDK编译的,然后在高版本的JDK版本中使用。 |
脚本中运行全部单元测试:
1 |
$ bash gradlew test |
打包编译发行版本:
1 |
$ bash gradlew clean assembleRelease |
最后,编译执行的JDK
的版本一般建议跟Android Studio
使用的JDK
一致,完全可以使用Android Studio
自带的JDK
进行编译。
1 2 3 4 5 6 7 8 |
$ echo "export JAVA_HOME='/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home'" >> ~/.bashrc $ source ~/.bashrc # 由于macOS Catalina 10.15.6已经切换到zsh了,因此需要配置zsh的配置文件 $ echo "export JAVA_HOME='/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home'" >> ~/.zprofile $ source ~/.zprofile |
当前建议的版本
1 2 3 4 |
$ java -version openjdk version "1.8.0_242-release" OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) OpenJDK 64-Bit Server VM (build 25.242-b3-6222593, mixed mode) |
目前,暂时不建议在生产环境中使用Android Studio 4.2发布版本,目前测试发现Android Studio 4.2编译出的代码,在华为系列手机上存在问题,主要是崩溃问题。可能出现如下崩溃日志:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** A/DEBUG: Build fingerprint: 'HONOR/BMH-AN10/HWBMH:10/HUAWEIBMH-AN10/11.0.0.168C00:user/release-keys' A/DEBUG: Revision: '0' A/DEBUG: ABI: 'arm64' A/DEBUG: SYSVMTYPE: Maple APPVMTYPE: Art A/DEBUG: Timestamp: 2021-05-10 17:32:02+0800 A/DEBUG: pid: 25826, tid: 25843, name: HeapTaskDaemon >>> com.xx.xxx <<< A/DEBUG: uid: 10587 A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10 A/DEBUG: Cause: null pointer dereference A/DEBUG: x0 00000079388b9200 x1 000000792cc8ea98 x2 0000000000000008 x3 000000007145cdf0 A/DEBUG: x4 0000000000000474 x5 000000001339122c x6 12ec18c812ec2148 x7 0000000071485dd0 A/DEBUG: x8 0000000000000000 x9 89793691a5863ce4 x10 0000000052c00000 x11 0000000000000008 A/DEBUG: x12 000000000000000b x13 000009ec00000079 x14 0005ffb86a66d4d9 x15 00000aff3f1ff8cb A/DEBUG: x16 00000079387f9e38 x17 00000079ba841b40 x18 00000078d47be000 x19 000000792cc8ea98 A/DEBUG: x20 000000007145cdf0 x21 0000000000000008 x22 0000000071bdb820 x23 0000000071bd9f98 A/DEBUG: x24 0000000000000028 x25 0000000000002a30 x26 000000792cc90020 x27 0000000000001888 A/DEBUG: x28 0000000071bd9fb0 x29 000000792cc8ea80 A/DEBUG: sp 000000792cc8ea10 lr 0000007938432790 pc 000000793843276c |
如果升级到Android Studio 4.2执行测试用例的时候,可能报告如下错误:
1 2 3 4 5 |
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.973 sec <<< FAILURE! - in com.Test initializationError(com.Test) Time elapsed: 0.007 sec <<< ERROR! org.objenesis.ObjenesisException: java.lang.reflect.InvocationTargetException Caused by: java.lang.reflect.InvocationTargetException Caused by: java.lang.IllegalAccessError: class jdk.internal.reflect.ConstructorAccessorImpl loaded by org/powermock/core/classloader/MockClassLoader cannot access jdk/internal/reflect superclass jdk.internal.reflect.MagicAccessorImpl |
这个问题是由于Android Studio 4.2自带的JDK版本已经升级到了Java 11.0.8版本,跟PowerMock不兼容。
解决此问题的方式是在测试用例的忽略列表中增加:
1 |
@PowerMockIgnore("jdk.internal.reflect.*") |
另外,在Android Studio 4.2使用Robolectric-4.5.1以下的版本(比如Robolectric-4.3.1)执行测试用例的时候,可能报告如下错误信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[Robolectric] : sdk=28; resources=BINARY Downloading from maven Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom from repository sonatype at https://oss.sonatype.org/content/groups/public/ Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext) [WARNING] Unable to get resource 'org.robolectric:android-all:pom:10-robolectric-5803371' from repository sonatype (https://oss.sonatype.org/content/groups/public/): Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext) Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom from repository central at http://repo1.maven.org/maven2 Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom [WARNING] Unable to get resource 'org.robolectric:android-all:pom:10-robolectric-5803371' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.pom Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar from repository sonatype at https://oss.sonatype.org/content/groups/public/ Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext) [WARNING] Unable to get resource 'org.robolectric:android-all:jar:10-robolectric-5803371' from repository sonatype (https://oss.sonatype.org/content/groups/public/): Error transferring file: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext) Downloading: org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar from repository central at http://repo1.maven.org/maven2 Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar [WARNING] Unable to get resource 'org.robolectric:android-all:jar:10-robolectric-5803371' from repository central (http://repo1.maven.org/maven2): Error transferring file: Server returned HTTP response code: 501 for URL: http://repo1.maven.org/maven2/org/robolectric/android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar |
这个问题是由于Android Studio 4.2自带的JDK版本已经升级到了Java 11.0.8版本,当Robolectric去服务器下载依赖包的时候,默认使用HTTP地址。当服务器强制要求重定向到HTTPS地址,这部分代码处理存在问题。
解决这个问题的方法就是升级到 Robolectric-4.5.1以及以上的版本即可。
在 Android Studio Chipmunk | 2021.2.1 Patch 1 以及以上的版本,当参照 Gradle传递System Property 配置在隔离环境中(公司内网/局域网)进行开发,在 Android Studio 上右键 “Debug ...”执行单元测试,可能会发生如下报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
URI is not absolute java.lang.IllegalArgumentException: URI is not absolute at java.base/java.net.URL.fromURI(URL.java:692) at java.base/java.net.URI.toURL(URI.java:1116) at org.robolectric.internal.dependency.MavenArtifactFetcher.getRemoteUrl(MavenArtifactFetcher.java:138) at org.robolectric.internal.dependency.MavenArtifactFetcher.fetchToStagingRepository(MavenArtifactFetcher.java:145) at org.robolectric.internal.dependency.MavenArtifactFetcher.fetchArtifact(MavenArtifactFetcher.java:65) at org.robolectric.internal.dependency.MavenDependencyResolver.lambda$getLocalArtifactUrls$0(MavenDependencyResolver.java:80) at org.robolectric.internal.dependency.MavenDependencyResolver.whileLocked(MavenDependencyResolver.java:100) at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrls(MavenDependencyResolver.java:75) at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrls(MavenDependencyResolver.java:65) at org.robolectric.internal.dependency.MavenDependencyResolver.getLocalArtifactUrl(MavenDependencyResolver.java:116) at org.robolectric.plugins.LegacyDependencyResolver.getLocalArtifactUrl(LegacyDependencyResolver.java:89) at org.robolectric.plugins.DefaultSdkProvider$DefaultSdk.getJarPath(DefaultSdkProvider.java:146) at org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader.<init>(AndroidSandbox.java:102) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) at org.robolectric.util.inject.Injector.inject(Injector.java:250) at org.robolectric.util.inject.Injector.lambda$memoized$1(Injector.java:232) at org.robolectric.util.inject.Injector$MemoizingProvider.get(Injector.java:498) at org.robolectric.util.inject.Injector.getInstanceInternal(Injector.java:224) at org.robolectric.util.inject.Injector.resolveDependencies(Injector.java:296) at org.robolectric.util.inject.Injector.inject(Injector.java:248) at org.robolectric.util.inject.Injector.lambda$memoized$1(Injector.java:232) at org.robolectric.util.inject.Injector$MemoizingProvider.get(Injector.java:498) at org.robolectric.util.inject.Injector.getInstanceInternal(Injector.java:224) at org.robolectric.util.inject.Injector.getInstance(Injector.java:208) at org.robolectric.util.inject.Injector.access$700(Injector.java:96) at org.robolectric.util.inject.Injector$ScopeBuilderProvider.create(Injector.java:564) at org.robolectric.util.inject.Injector$ScopeBuilderProvider.lambda$get$0(Injector.java:547) at com.sun.proxy.$Proxy19.build(Unknown Source) at org.robolectric.internal.SandboxManager.getAndroidSandbox(SandboxManager.java:57) at org.robolectric.RobolectricTestRunner.getSandbox(RobolectricTestRunner.java:285) at org.robolectric.RobolectricTestRunner.getSandbox(RobolectricTestRunner.java:68) at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:236) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:93) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38) at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176) at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129) at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100) at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60) at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56) at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133) at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71) at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69) at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74) |
该报错的原因是 Android Studio 没有正确读取我们配置的 robolectric.dependency.repo.url 环境变量,导致无法成功下载,当然也可能是由于高版本不支持 HTTP ,链接地址必须是 HTTPS 导致此问题,这个没有深究。
解决方法是,在命令行执行
1 |
$ bash gradlew clean build -Drobolectric.dependency.repo.url=http://127.0.0.1/jcenter |
确保在当前用户目录下的 .m2 目录下,成功完成 robolectric 需要的全部文件的下载。这样,执行测试用例的时候,就可以从本地获取依赖文件,而不需要再去服务器上获取。
当升级到 Android Studio Flamingo | 2022.2.1 Patch 2 之后,内置的 Java 版本被升级到 Java 17 ,这个 Java 版本执行单元测试,会报错。解决方案参考 Android Studio Flamingo | 2022.2.1 Patch 2 配置Robolectric-3.8/4.3.1/4.5.1/4.6.1单元测试环境。
参考链接
- Robolectric unit tests fail after Multidex
- Multidex support #1328
- Robolectric と Multidex でテストが落ちる問題の対応
- Robolectric测试框架使用笔记
- java.lang.VerifyError: Expecting a stackmap frame at branch target 17 #144
- Configuring Robolectric
- Android Studio 2.1.3配置Robolectric-3.0,Powermock-1.6.5单元测试环境
- Robolectric Using PowerMock
- Android单元测试(七):Robolectric介绍
- Android MultiDex实践:如何绕过那些坑?
- Idea debug时报错:Command line is too long
- Windows 10 Build 14352版中已经可以去除260字符的路径长度限制
- Windows 平台上长路径名文件的解决方法
- java.lang.VerifyError: Expecting a stackmap frame at branch target JDK 1.7如何解决?
- Jvm options in android when run gradlew test
- Unit testing support
- Gradle - equivalent of test {} configuration block for android
- Robolectric cannot download artifacts - all tests fail #5456
- MockClassLoader cannot access jdk/internal/reflect superclass jdk.internal.reflect.MagicAccessorImpl
- PowerMock & Java 11
- Android Studio release notes
- 加速Robolectric下载依赖库