android - ApplicationTestCase deprecated in API level 24 -
i created default empty project on android studio 2.1.2 api 24. in sample project, google offers depreciated class applicationtestcase:
this class deprecated in api level 24. use activitytestrule instead. new tests should written using android testing support library.
sample:
import android.app.application; import android.test.applicationtestcase; /** * <a href="http://d.android.com/tools/testing/testing_android.html">testing fundamentals</a> */ public class applicationtest extends applicationtestcase<application> { public applicationtest() { super(application.class); } }
my question: why android test case deprecated? how replace applicationtestcase activitytestrule?
edit:
i try expresso, on api 24 (compilesdkversion 24
) have error:
error:conflict dependency 'com.android.support:appcompat-v7'. resolved versions app (24.0.0) , test app (23.1.1) differ. see http://g.co/androidstudio/app-test-app-conflict details. error:conflict dependency 'com.android.support:design'. resolved versions app (24.0.0) , test app (23.1.1) differ. see http://g.co/androidstudio/app-test-app-conflict details. error:conflict dependency 'com.android.support:support-annotations'. resolved versions app (24.0.0) , test app (23.1.1) differ. see http://g.co/androidstudio/app-test-app-conflict details. error:conflict dependency 'com.android.support:recyclerview-v7'. resolved versions app (24.0.0) , test app (23.1.1) differ. see http://g.co/androidstudio/app-test-app-conflict details.
when try add lib in build.gradle:
// android junit runner androidtestcompile 'com.android.support.test:runner:0.5' // junit4 rules androidtestcompile 'com.android.support.test:rules:0.5' // espresso core androidtestcompile 'com.android.support.test.espresso:espresso-core:2.2.2' // espresso-contrib datepicker, recyclerview, drawer actions, accessibility checks, countingidlingresource androidtestcompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' // espresso-web webview support androidtestcompile 'com.android.support.test.espresso:espresso-web:2.2.2' // espresso-idling-resource synchronization background jobs androidtestcompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
my conclusion moment neither android test case nor expresso works on android api 24. right?
edit: 2016-08-05
i fix previous error on expresso that:
def espressoversion = '2.2.2' def testrunnerversion = '0.5' androidtestcompile "com.android.support.test:rules:${testrunnerversion}" androidtestcompile "com.android.support.test.espresso:espresso-core:${espressoversion}" configurations.androidtestcompile.dependencies.each { androidtestcompiledependency -> androidtestcompiledependency.exclude group: 'com.android.support' }
the new androidtest example beta version of android studio 2.2 generates, this:
@runwith(androidjunit4.class) public class exampleinstrumentedtest { @test public void useappcontext() throws exception { // context of app under test. context appcontext = instrumentationregistry.gettargetcontext(); assertequals("org.mypackage", appcontext.getpackagename()); } }
just deprecation warning suggests, new instrumentation tests should use instrumentationregistry
instead of extending androidtestcase
. run them androidjunit4
.
the relevant dependencies
section in build.gradle
looks this:
androidtestcompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' })
Comments
Post a Comment