Tag: android instrumentation

从Android Studio中的播放图标开始检测测试,将它们作为JVM上的JUnit运行

当我尝试在Android Studio中通过单击文件左侧的装订线中的播放图标来运行检测测试时,它会创建错误的运行配置。 我正在使用Android Studio 3.0.1。 这似乎只发生在测试写在Kotlin。

java.lang.NoClassDefFoundError:kotlin.jvm.internal.Intrinsics – newApplication

问题 我只是试图将自定义的AndroidJUnitRunner类从Java转换到Kotlin。 码 CustomTestRunner.java public class CustomTestRunner extends AndroidJUnitRunner { @Override public Application newApplication(ClassLoader cl, String className, Context context) throws IllegalAccessException, ClassNotFoundException, InstantiationException { return super.newApplication(cl, TestApp.class.getName(), context); } } CustomTestRunner.kt – (导致错误 – 请参阅下面的堆栈跟踪) class CustomTestRunner : AndroidJUnitRunner() { override fun newApplication(cl: ClassLoader, className: String, context: Context): Application { return super.newApplication(cl, TestApp::class.java.name, context) } […]

未能在新的Android Kotlin项目上运行Instrumented测试

我刚刚创建了一个新的Android应用程序与Kotlin支持。 当我试图运行默认的仪器测试时,它不会运行,并显示给我这个消息: Class not found: “oussaki.com.pos.ExampleInstrumentedTest”Empty test suite. 这是我试图运行的Instrumented测试类: @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getTargetContext() assertEquals(“oussaki.com.pos”, appContext.packageName) } }

Android Kotlin仪器测试不被识别为仪器测试

我正在尝试在我的Android项目中编写一个kotlin工具测试。 这一刻是非常基本的: class SimpleTest { @Test fun aTest() { Assert.assertTrue(true) } } 当我运行它时,它说no tests were found 。 但是当我运行这个类的Java版本时,系统会提示选择我要运行测试的设备(意思是AS将其识别为仪器测试)。 Java版本看起来像这样: public class AnyTest { @Test void aTest() { Assert.assertTrue(true); } } 如果我然后将这个Java类转换为Kotlin并重新运行测试,我得到相同的no tests were found 。 我在这里错过了什么? 谢谢

Android测试失败时,Gradle构建失败,“字符串索引超出范围”

尝试使用Android进行仪器测试时遇到问题。 当其中一个测试失败时,构建失败,但没有声明测试失败。 相反,我得到FAILURE: Build failed with an exception. 对于出错的部分,我得到的String index out of range: -1 。 在我真正的应用程序,这是导致它不生成一个HTML报告,并且XML报告零星生成。 我已经把一个简单的测试用例放在一起,但它正在生成报告,但是另外给出了相同的失败消息。 为了澄清, 测试旨在失败,但我期望一个A test has failed消息,而不是看起来像一个不同的失败原因。 我怀疑这个失败正在导致构建生命周期中的其他事情导致我所看到的信息出错。 这是非常简单的测试应用程序 的build.gradle buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.4.0-alpha7' } } apply plugin: 'com.android.application' repositories { jcenter() mavenCentral() } dependencies { androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.2" androidTestCompile "com.android.support.test.espresso:espresso-intents:2.2.2" androidTestCompile "com.android.support.test:runner:0.5" } […]

Android:仪器运行失败,由于“java.lang.ClassNotFoundException”:未找到测试

我尝试通过“gradlew connectedAndroidTest”运行一个仪器测试。 我得到以下错误: Tests on GT-I9305 – 4.3 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException' com.android.builder.testing.ConnectedDevice > hasTests[GT-I9305 – 4.3] FAILED No tests found. :mobile:connectedAndroidTest FAILED 这是带有–stacktrace选项的输出: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':mobile:connectedAndroidTest'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305) at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79) […]

java.lang.VerifyError在Kotlin中编写Android测试的特性

我正在尝试为Android的InstrumentationTestCase创建一个包含抽象属性和使用此属性的方法的特征。 不幸的是,当我运行这个测试它崩溃与java.lang.VerifyError 。 所以这是一个导致崩溃的代码示例: trait ExtendedInstrumentationTestCase : InstrumentationTestCase { val string: String fun printString(): Unit { println(string) } } class MyApplicationTestCase : ApplicationTestCase<Application>(javaClass<Application>()), ExtendedInstrumentationTestCase { override val string: String = "test" override fun setUp() { super<ApplicationTestCase>.setUp() printString() } override fun tearDown() { super<ApplicationTestCase>.tearDown() } } 这就是我从logcat得到的结果: W/dalvikvm﹕ VFY: Lcom/kotlintest/MyApplicationTestCase; is not instance of Landroid/test/InstrumentationTestCase; W/dalvikvm﹕ […]