从Android Studio中的单元测试分离集成测试 [英] Separating integration tests from unit tests in Android Studio

查看:331
本文介绍了从Android Studio中的单元测试分离集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android Studio中0.9分离出集成测试。

我已经添加了以下到生成文件:

  sourceSets {
    integrationTest {
        java.srcDir文件('SRC / integrationTest / Java的)
    }
}任务integrationTest(类型:测试){
    testClassesDir = sourceSets.integrationTest.output.classesDir
    CLASSPATH = sourceSets.integrationTest.runtimeClasspath
}

我碰到几个问题:


  1. 该任务将运行,但它没有提供该项目的其他文件,所以我得到有关缺失类的错误。还有我发现,如一些Java的具体解决方案:

    但我一直无法弄清楚如何得到这个与Android工作室工作。的 main.output 和依赖玩弄各种组合似乎不工作,我得到这样的错误

     错误:(33,0)无法在SourceSet容器找物业的主要'..

    由于Android插件定义了自己的源代码集,但这些都不要么工作,这是有道理的。


  2. IDE将无法识别该目录作为测试源目录。出于测试目的,我改变了源集名称 androidTest 并正确得到绿色的文件夹图标和测试与在<$已经定义现有的单元测试一起运行C $ C> androidTest 。



解决方案

我已经做正是这种在摇篮分离的,但对于一个纯Java的项目,而不是Android系统。你是不是在指定源套,我认为这是问题的类路径。下面是相关的部分的的build.gradle

  sourceSets {
    整合{
        java的{
            compileClasspath + = main.output + test.output
            runtimeClasspath + = main.output + test.output
            SRCDIR文件('SRC /集成/ Java的)
        }
        资源{
            SRCDIR的src /集成/资源
        }
    }
}配置{
    integrationCompile.extendsFrom testCompile
    integrationRuntime.extendsFrom testRuntime
}任务integrationTest(组:核查,type:测试){
    testClassesDir = sourceSets.integration.output.classesDir
    CLASSPATH = sourceSets.integration.runtimeClasspath
}
integrationTest.dependsOn testClasses

IntelliJ IDEA的在的src /集成拿起文件夹,如果他们有标准名称(Java中,资源)。

I'm trying to separate out integration tests in Android Studio 0.9.

I have added the following to the build file:

sourceSets {
    integrationTest {
        java.srcDir file('src/integrationTest/java')
    }
}

task integrationTest(type: Test) {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
}

I've run into a couple of issues:

  1. The task will run but it doesn't have the rest of the project files available so I get errors about missing classes. There are some Java specific solutions I've found such as:

    But I haven't been able to figure out how to get this to work with Android Studio. Various combinations of main and main.output and playing around with dependencies don't seem to work, I get errors like:

    Error:(33, 0) Could not find property 'main' on SourceSet container..
    

    Which makes sense as the android plugin defines its own source sets, but these don't work either.

  2. The IDE doesn't recognise the directory as a test source directory. For testing purposes I changed the source set name to androidTest and it correctly gets the green folder icon and the tests are run along with the existing unit tests that are already defined in androidTest.

解决方案

I've done exactly this kind of separation in Gradle, but for a pure Java project, not Android. You are not specifying the classpath in source sets, which I think is the issue. Here's the relevant part of the build.gradle:

sourceSets {
    integration {
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration/java')
        }
        resources {
            srcDir 'src/integration/resources'
        }
    }
}

configurations {
    integrationCompile.extendsFrom testCompile
    integrationRuntime.extendsFrom testRuntime
}

task integrationTest(group: "verification", type: Test) {
    testClassesDir = sourceSets.integration.output.classesDir
    classpath = sourceSets.integration.runtimeClasspath
}
integrationTest.dependsOn testClasses

IntelliJ idea picks up the folders under src/integration if they have the standard names (java, resources).

这篇关于从Android Studio中的单元测试分离集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆