即使在androidTest包中,Kotlin类也会作为junit测试运行 – 对于Java类,它运行正常
我遇到了非常奇怪的错误。
当我尝试运行测试,在我的Kotlin类的androidTest包,他们正在运行测试junit mehthods,并出现此错误:
处理完成退出代码1未find类:“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 Instrumentation测试而不是Android JUnit创建一个。
- kodein,将数据注入简单的类
- 使用Android NDK处理现有的iOS应用程序
- 在android kotlin中,使用步进库将自定义单选按钮值传递给多个片段,以便在摘要页面上使用
- 如何在Kotlin中使用AndroidAnnotation @FragmentArg?
- com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期的BEGIN_ARRAY,但在第1行第2列的路径
- Kotlin recyclerview给了我空指针例外
- RealmObject的Kotlin数据类
- 一些绘图不能被发现
- 是否有可能使用Java 8进行Android开发?