繁体   English   中英

Android Studio gradle实验测试(JUNit)

[英]Android Studio gradle experimental test (JUNit)

我正在尝试使用InstrumentationTestCase测试我的课程。 我一直在检查示例,但我想我错过了一些东西,因为“Test Artifact”下拉列表被禁用,无法更改为JUNit。

我在gradle中声明了这些库

// Test Compile
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.reflections:reflections:0.9.9'

申报的应用ID,

defaultConfig {
    testApplicationId "myproject.android.test"
  }

并获得最新的gradle版本

dependencies {
        classpath 'com.android.tools.build:gradle:+'
    }

还为我的测试包创建了一个构建配置。 但是当我进行测试时,它给了我

Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter

可能是因为Test Artifact是“Android Instrumentation Tests”而构建配置是JUNit配置。 Test Artifact下拉列表已禁用,因此我无法将其更改为JUNit。 有什么东西我不见了吗?

编辑:我的包树是这样的,

myproject
 - app
   - main
    - java
      -myproject
       -android
        -mypackage
         -myclass.java
   -test
    -java
     -myproject
      -android
       -mypackage
        -test
         -myclasstest.java

在Android Studio首选项中,在Gradle-> Experimental下,选中“启用单元测试支持”。

您需要执行几个步骤来激活Android Studio中的JVM单元测试。 请按以下步骤操作: https//sites.google.com/a/android.com/tools/tech-docs/unit-testing-support

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM