Android Gradle 1.1 - 添加对另一个项目的测试的测试依赖 [英] Android Gradle 1.1 - adding a test dependency on another project's tests

查看:19
本文介绍了Android Gradle 1.1 - 添加对另一个项目的测试的测试依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个模块:AB.

I have 2 modules: A and B.

-A 是一个独立的模块.它的测试本身运行得很好.
-B 是一个依赖模块.它的测试需要A的测试文件夹中的某个文件(B中的一个测试文件扩展A中的一个)

-A is a standalone module. Its tests run just fine all by itself.
-B is a dependent module. Its tests require a certain file in A's test folder (one test file in B extends one in A)

 

以下是我认为 Bbuild.gradle 的相关部分:

Here are what I believe to be the relevant parts of B's build.gradle:

android { 
  ...
  sourceSets {
    test.java.srcDirs += "../A/src/test/java"
  }
}

dependencies {
  compile project(':A')

  testCompile 'junit:junit:4.10'
  testCompile 'org.robolectric:robolectric:2.4'
  testCompile 'org.mockito:mockito-core:1.9.5'
}

虽然这在技术上可以满足我的需要 - 它有一个令人讨厌的副作用,即每当我运行 A 的单元测试时,它们也会运行所有 B's 测试.如果不是这样,我真的很希望.

While this technically works for what I need it - it has the nasty side effect that whenever I run A's unit tests, they also run all of B's tests. I would really like if this was not the case.

 

我使用的是 Android Gradle 1.1(以及 Android Studio 1.1),我认为这给我带来了一些问题.我已经尝试了我能找到的所有解决方案 - 不幸的是,它们似乎都不适用于 Android Gradle 1.1 - 例如:

I am using Android Gradle 1.1 (along with Android Studio 1.1), and I think this is causing me some issues. I have tried all the solutions I could find - unfortunately, none of them seem to apply for Android Gradle 1.1 - for example:

Bbuild.gradle 中删除 sourceSets 并添加(到 B 的依赖项)线

Removing the sourceSets from B's build.gradle and adding (to B's dependencies) the line

 testCompile project(':A').sourceSets.test.output

产生构建错误在 SourceSet 容器上找不到属性test".

 

我是不是用错了方法?有没有更简单/更好的方法来跨模块包含测试文件?我对 Gradle/Android Studio 还很陌生,所以我完全有可能错过了一个显而易见的解决方案.

Am I going about this the wrong way? Is there an easier/better way to include test files across modules? I'm pretty new to Gradle/Android Studio, so it's totally possible I'm missing a dead obvious solution.

推荐答案

使用命令按树检查所有模块:

Check all your modules by tree using command:

gradle projects

它将列出您的所有项目模块,您可以查看是否以正确的方式配置您的子项目.同时运行命令:

It will list all your project modules and you can see if you are configuring your sub projects in a right way. Also run command:

gradle --gui

它将列出所有模块的所有任务,并且您始终可以独立于其他模块运行一个模块,例如

It will list all the tasks for all modules, and you can always run one module independently from other e.g.

gradle A:tasks
gradle A:test
gradle B:test

或两者

gradle A:tasks B:test

注意:如果是根项目和B、C、D子模块,则不需要指定A,但对于子模块则需要指定.当你这样做时:

Note: You do not need to specify the A if it is the root project and B,C,D sub-modules but for submodules you need to specify it. When you do:

gradle --gui

您可以双击任何任务来查看它是如何运行的,您也可以从命令行手动执行相同的操作.希望这有帮助

You can double click on any task to see how it runs and you can do the same manually from command line. Hope this helps

这篇关于Android Gradle 1.1 - 添加对另一个项目的测试的测试依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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