Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@SmallTest, @MediumTest, and @LargeTest deprecated on Android

Tags:

android

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?

like image 556
Víctor Albertos Avatar asked Jul 24 '16 11:07

Víctor Albertos


4 Answers

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:

  1. Be sure you're using import android.support.test.filters.<size>Test at the top of your test file.
  2. Ensure your test 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'
like image 153
Chris Lacy Avatar answered Oct 16 '22 13:10

Chris Lacy


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; 
like image 27
giorgos.nl Avatar answered Oct 16 '22 13:10

giorgos.nl


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;
like image 38
gabocalero Avatar answered Oct 16 '22 13:10

gabocalero


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;
like image 38
Khaled Saifullah Avatar answered Oct 16 '22 11:10

Khaled Saifullah