我遇到了非常奇怪的错误。
当我尝试在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)
}
}
它给了我这个错误。
怎么了?