一种可能的解决方法是在测试代码中添加以下依赖项:
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
这个依赖项将允许测试代码引用Android类。另一种可能的解决方法是在测试类中添加@RunWith(JUnit4.class)
注释,以确保测试使用正确的测试运行器。例如:
@RunWith(JUnit4.class)
public class MyAndroidUnitTest {
// Test methods go here
}