从多个模块一起在IntelliJ IDEA中运行单元测试 [英] Run unit tests in IntelliJ IDEA from multiple modules together

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

问题描述

如何一次从两个或多个IDEA模块运行所有测试?

How can I run all tests from two or more IDEA modules at once?

我正在使用许多模块,因此经常运行所有单元测试非常重要,并且当我选择运行多个文件夹时,上下文菜单上不再有运行"选项.

I'm using many modules and it is important to run all of the unit tests often and when I choose more than one folder to run, there's no 'run' option on the context menu any more.

推荐答案

最佳方法:(3年后编辑)

甚至有更好的方法可以实现这一目标.

There is even a better way to achieve this.

  1. 选择菜单运行"→编辑配置...".单击左上角的绿色加号,然后选择JUnit.

  1. Select menu "Run" → "Edit Configurations...". Click green plus in left top corner and select JUnit.

在模式"中选择测试种类",然后完全按照您所见的方式输入此正则表达式:^(?!.*IT$).*$(以插入号^开头,以美元$结尾).该正则表达式表示:所有未以IT名义完成的测试.

Select "Test kind" to "Pattern" and enter this regexp exactly as you see it: ^(?!.*IT$).*$ (it starts with caret ^ and ends with dollar $). This regexp says: all tests that do not finish with IT in their name.

将搜索测试"选择为在整个项目中".工作目录应设置为顶部模块工作目录(默认情况下应设置).

Select "Search for tests" to "In whole project". Working directory should be set to top module working directory (it should be set by default).

为您的测试输入名称,例如所有单元测试".我也更喜欢标记共享"选项,这样此配置以后就不会消失.单击应用",然后单击确定".

Enter a Name for your test like "All Unit tests". I also prefere to mark "Share" option so this configuration won't disappear later. Click Apply and OK.

您可以尝试使用此正则表达式来满足您的需求.

You can experiment with this regexp to fit your needs.

原始答案:

这是可行的,尽管不舒服.

It is doable, although it's not comfortable.

  1. 选择第一个模块,右键单击test/java目录,然后单击运行所有测试".它会创建测试配置.
  2. 选择编辑配置",然后在新创建的配置上选中共享",以便将其保存.
  3. 选择第二个模块,在其上运行所有测试",并在此配置上也选中共享".
  4. 在启动前"部分中,单击"+"并选择运行其他配置",然后选择第一个模块的配置.
  1. Select first module, right-click on test/java directory and "Run All Tests". It creates test configuration.
  2. Select "Edit configurations" and check "Share" on newly created configuration so it will be saved.
  3. Select second module, "Run All Tests" on it, and check "Share" on this configuration as well.
  4. In "Before launch" section, click "+" and select "Run Another Configuration" and then select first module's configuration.

通过这种方式,您可以按顺序运行配置,并且每个配置都有一个新选项卡.尽管如此,总比没有好.

This way you run configurations in a sequence and every configuration gets a new tab. Still, better than nothing.

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

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