在IntelliJ中运行单元和集成测试 [英] Running Unit and Integration Tests in IntelliJ

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

问题描述

在我的Java项目中,我目前有两套不同的测试:
$ b

  • 单元测试

  • 集成测试 - 这些使用Arquillian在容器中运行



我目前使用Gradle作为构建脚本,并使用JetGradle与IntelliJ 12 。在我的Gradle构建脚本中,我必须设置测试类路径:


  • testCompile - 这是单元的标准测试配置在Gradle中进行测试,并映射到IntelliJ中的测试范围。

  • integrationTestCompile - 这是一个自定义测试配置,其中包含集成测试使用的其他Arquillian依赖项。这当前不会映射到IntelliJ中的作用域




IntelliJ中是否有任何方法来管理单独的测试集类路径之一为单元测试,一个为集成测试,并使用集成IntelliJ测试运行器来运行一个或另一个?



目前我已通过添加所有测试依赖于IntelliJ测试范围,但我希望在运行单元测试时不必包含集成依赖关系。



唯一的另一个解决方案是创建单独的集成测试模块和它自己的类路径,但这并不理想。

解决方案

IDEA,因为后者只支持一组固定的范围(强烈启发来自Maven)。但是,可以配置Gradle IDEA插件来映射 testCompile integrationTestCompile (以及相应的运行时配置)到IDEA的测试范围。从你的描述中,我不确定你是否已经这样做过。


I currently have two different sets of tests in my Java project:

  • Unit tests
  • Integration tests - these use Arquillian to run in a container

I currently use Gradle as my build script and JetGradle to integrate with IntelliJ 12. In my Gradle build script I have to sets of test class paths:

  • testCompile - This is the standard test configuration for unit tests in Gradle and maps to the test scope in IntelliJ.

  • integrationTestCompile - This is a custom test configuration with the additional Arquillian dependencies used by the integration tests. This does not currently get mapped to a scope in IntelliJ

Is there any way in IntelliJ to manage separate sets of test class paths one for unit tests and one for integration tests and use the integrated IntelliJ test runner to run one or the other?

Currently I have worked round this by adding all test dependencies to the IntelliJ test scope but I would like to not have to include the integration dependencies when running unit tests.

The only other solution I can find is to create a separate integration test module with it's own class path but this is not ideal.

解决方案

It isn't possible to have separate test scopes in IDEA because the latter only supports a fixed set of scopes (strongly inspired from Maven). It is, however, possible to configure the Gradle IDEA plugin to map both testCompile and integrationTestCompile (and also the corresponding runtime configurations) to IDEA's test scope. From your description, I'm not sure if you have already done that.

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

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