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