Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
@Android上不推荐使用SmallTest、@MediumTest和@LargeTest_Android - Fatal编程技术网

@Android上不推荐使用SmallTest、@MediumTest和@LargeTest

@Android上不推荐使用SmallTest、@MediumTest和@LargeTest,android,Android,最近,Android上已经弃用了这3种注释@SmallTest、@MediumTest和@LargeTest 但我找不到任何文档来解释动机或提出新的注释集 那么,现在有没有办法声明测试的范围 以前,这些注释位于android.test.suitebuilder.annotation包中。从API 24开始,它们被移动到android.support.test.filters包中(为@MediumTest@SmallTest和@LargeTest编写的文档是相同的) 要使用新版本,请执行以下操作:

最近,Android上已经弃用了这3种注释
@SmallTest
@MediumTest
@LargeTest

但我找不到任何文档来解释动机或提出新的注释集


那么,现在有没有办法声明测试的范围

以前,这些注释位于
android.test.suitebuilder.annotation
包中。从API 24开始,它们被移动到
android.support.test.filters
包中(为
@MediumTest
@SmallTest
@LargeTest
编写的文档是相同的)

要使用新版本,请执行以下操作:

  • 确保您正在测试文件顶部使用导入android.support.test.filters.test
  • 确保您的测试
    runner
    rules
    版本在
    build.gradle
    文件中至少使用了0.5版本:
    
    androidTestCompile'com.android.support.test:runner:0.5'
    androidTestCompile'com.android.support.test:规则:0.5'
    

  • androidx的更新

    在应用程序的
    build.gradle
    中声明的依赖项:

    androidTestImplementation'androidx.test:runner:1.2.0'

    然后导入看起来像:

    import androidx.test.filters.SmallTest;
    import androidx.test.filters.MediumTest;
    import androidx.test.filters.LargeTest;
    import androidx.test.filters.FlakyTest;
    
    原始答案

    正如Chris所说,从API 24开始,这些应用程序将被移动到API中(针对此API的应用程序将继续)

    为了使用JUnit/单元测试的注释,您必须添加:

    testImplementation 'com.android.support.test:runner:0.5'
    
    build.gradle
    文件中

    对于UI/instrumentation测试,添加:

    androidTestImplementation 'com.android.support.test:runner:0.5'
    
    然后在测试类中添加一个/多个以下导入:

    import android.support.test.filters.SmallTest;
    import android.support.test.filters.MediumTest;
    import android.support.test.filters.LargeTest;
    import android.support.test.filters.FlakyTest;
    

    步骤1:在应用程序的
    build.gradle
    文件中,在
    依赖项内部添加:

    testImplementation 'com.android.support.test:runner:1.0.2'
    
    请注意:您必须将此行添加为
    testImplementation
    ,而不是
    androidTestImplementation

    第2步:在测试类中,添加一个/多个以下导入(根据需要)


    androidx的更新

    步骤1:在应用程序的build.gradle文件中,添加内部依赖项:

    testImplementation 'androidx.test:runner:1.1.1'
    testImplementation 'androidx.test:rules:1.1.1'
    
    步骤2:在测试类中,添加所需的导入

    import androidx.test.filters.LargeTest;
    import androidx.test.filters.MediumTest;
    import androidx.test.filters.SmallTest;
    

    谢谢你,克里斯。我已经为rules和runner使用了0.5版本,但它无法解析这样的包。请共享一个完整的gradle配置依赖项块以检查我的当前配置,好吗?您是否1000%确定导入语句正确?他们应该指向导入android.support.test.filters.test
    。是。它无法解决“android.support.test.filters”包。我和@VíctorAlbertosAlright有同样的问题,我想,这是因为
    test
    实际上是用于仪器测试的。如果您在Test文件夹(不是androidTest文件夹)中获得
    Test
    ,则仅在智能感应导入时显示
    *
    。我有
    androidTestCompile'com.android.support.Test:runner:0.5'
    ,AS无法解析
    import android.support.Test.filters.LargeTest您是否在单元测试中使用此导入(src/test下的类文件)?因为如果是这样,那么您需要使用
    testCompile'com.android.support.test:runner:0.5'
    如果您不确定,请提供您使用导入的类文件的完整路径。testCompile在new Gradle上不推荐使用
    import androidx.test.filters.LargeTest;
    import androidx.test.filters.MediumTest;
    import androidx.test.filters.SmallTest;