Robolectric是否需要Java 9? [英] Does Robolectric require Java 9?

查看:77
本文介绍了Robolectric是否需要Java 9?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有测试都通过了,但是我得到了以下警告.Robolectric告诉我Java 9是必需的.我正在使用最新版本的Robolectric.

All the tests are passing, but I get the below warning. Robolectric is telling me that Java 9 is required. I am using the latest version of Robolectric.

[Robolectric] WARN: Android SDK 10000 requires Java 9 (have Java 8). Tests won't be run on SDK 10000 unless explicitly requested.
[Robolectric] com.example.testcaseWithRobolectric.MainActivityTest.testAllElements: sdk=28; resources=BINARY
Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28

以退出代码0结束的过程

Process finished with exit code 0

这是我的摇篮:

    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'
        implementation project(path: ':domain_layer')
        testImplementation "org.robolectric:robolectric:4.3"
    }

defaultConfig {
        applicationId "com.example.testcaseWithRobolectric"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

推荐答案

在测试类中,您需要使用sdk数组作为参数的@Config进行注释.

on your test class, you need to annotate with @Config with an array of sdk as a parameter.

@Config(sdk = {Build.VERSION_CODES.O_MR1})
class SampleTest {}

对于Kotlin

@Config(sdk = [Build.VERSION_CODES.O_MR1])
class SampleTest {}

您的测试应该运行.

这篇关于Robolectric是否需要Java 9?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆