These 3 annotations @SmallTest, @MediumTest, and @LargeTest has been recently deprecated on Android.
But I couldn't find any documentation which explains the motivation or proposes a new annotation set.
So, is there any way right now for declaring the scope of a test?
Previously these annotations were in the android.test.suitebuilder.annotation package. As of API 24, they were moved to the android.support.test.filters package (documented here for @MediumTest. @SmallTest and @LargeTest are the same).
To use the new versions:
import android.support.test.filters.<size>Test at the top of your test file. runner and rules versions are using at least version 0.5 in your build.gradle file: androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:rules:0.5' Update for androidx
dependency declared in app's build.gradle:
androidTestImplementation 'androidx.test:runner:1.2.0'
and then imports looks like:
import androidx.test.filters.SmallTest; import androidx.test.filters.MediumTest; import androidx.test.filters.LargeTest; import androidx.test.filters.FlakyTest; Original answer:
Like Chris said, they are moved in the Testing Support Library as of API 24 (apps targeting this api onwards)
In order to use the annotations for JUnit/Unit tests you have to add:
testImplementation 'com.android.support.test:runner:0.5' in your build.gradle file
and for UI/instrumentation tests add:
androidTestImplementation 'com.android.support.test:runner:0.5' Then in your test class add one/more of the following imports:
import android.support.test.filters.SmallTest; import android.support.test.filters.MediumTest; import android.support.test.filters.LargeTest; import android.support.test.filters.FlakyTest;
Update for androidx
Step 1: In your app's build.gradle file, inside dependencies add:
testImplementation 'androidx.test:runner:1.1.1'
testImplementation 'androidx.test:rules:1.1.1'
Step 2: In your test class, add the needed imports
import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
Step 1: In your app's build.gradle file, inside dependencies add:
testImplementation 'com.android.support.test:runner:1.0.2'
Please note that: You have to add this line as testImplementation, not androidTestImplementation
Step 2: In your test class, add one/more of the following imports (Based on your need)
import android.support.test.filters.SmallTest;
import android.support.test.filters.MediumTest;
import android.support.test.filters.LargeTest;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With