Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

android - AndroidJUnit4.class is deprecated: How to use androidx.test.ext.junit.runners.AndroidJUnit4?

For my instrumentation tests I was using

@RunWith(AndroidJUnit4.class)

from

import androidx.test.runner.AndroidJUnit4;

in order to establish my test cases. Now this line gets marked as deprecated with the hint to use AndroidJUnit4 from

import androidx.test.ext.junit.runners.AndroidJUnit4

However if I try to import AndroidJUnit4 from the named package I get the error, that ext can not be resolved.

Do you have an idea, what package should be included in gradle to resolve this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to the documentation for AndroidJUnit4,

  1. The gradle file should contain the following line:

androidTestImplementation 'androidx.test.ext:junit:1.1.1'

  1. Change test class to AndroidJUnit4ClassRunner from AndroidJUnit4

If it still doesn't work, make sure that you clean and/or rebuild your project. Also you can check the current version directly in Google's maven repository


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...