我遇到了很奇怪的错误。
当我尝试在androidTest包中运行我的Kotlin类中的测试时,它们作为测试junit mehthods运行并出现此错误:
进程已完成退出代码1未找到类:“com.someampp.shoppinglistapp.SomeClassTest”空测试套件。
你可以自己试试。我使用的是Android Studio 3.0.1
当我在Java中创建这样的类时:
@RunWith(AndroidJUnit4.class)
public class SomeTestClass{
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.myapp.shoppinglistapp", appContext.getPackageName());
}
}
一切正常。
但是当我将Java文件转换为Kotlin时:
@RunWith(AndroidJUnit4::class)
class SomeTestClass{
@Test
@Throws(Exception::class)
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.myapp.shoppinglistapp", appContext.packageName)
}
}
它给了我这个错误。
怎么了?
您需要打开Run/Debug configurations
并为Android Instrumented Tests而不是Android JUnit创建一个。