简体   繁体   English

使用 IntelliJ Idea 进行持续测试

[英]Continuous testing with IntelliJ Idea

I'm looking for an IntelliJ IDEA plugin that would run my tests each time I change my code.我正在寻找一个 IntelliJ IDEA 插件,它可以在我每次更改代码时运行我的测试。 I looked for such a solution and I found:我寻找这样的解决方案,我发现:

  • Infinitest , which works, but is inconvenient because I need to add the facet to each module, and it opens a new tool window for each module (which means 15 tool windows for me). Infinitest ,它可以工作,但很不方便,因为我需要将 facet 添加到每个模块,并且它为每个模块打开一个新的工具窗口(这对我来说意味着 15 个工具窗口)。
  • Fireworks - didn't work for me, maybe it just doesn't work with IDEA 14 (in its repo I can see that last changes were made in 2009). Fireworks - 对我不起作用,也许它不适用于 IDEA 14(在它的 repo 中,我可以看到最后一次更改是在 2009 年进行的)。 IntelliJ also reports that it throws exceptions. IntelliJ 还报告它会引发异常。

There are lots of ways I could run all my tests (including writing a simple script for this), but I'm looking for a tool that would be smart enough to rerun failed tests first, and that would understand module dependencies (so after a change in some module it would run only tests of dependent modules).有很多方法可以运行我所有的测试(包括为此编写一个简单的脚本),但我正在寻找一种工具,它足够聪明,可以首先重新运行失败的测试,并且可以理解模块依赖关系(所以在在某些模块中更改它只会运行依赖模块的测试)。

I prefer free options, but if there's something paid for a reasonable price, I would accept it as well.我更喜欢免费的选择,但如果有以合理价格支付的东西,我也会接受。

IntelliJ now actually has a Toggle auto-test in the run dialog. IntelliJ 现在实际上在运行对话框中有一个Toggle auto-test Just run a run-configuration and then select Toggle auto-test in the run dialog.只需运行运行配置,然后在运行对话框中选择Toggle auto-test

It's not as intelligent as you would have hoped.它并不像你希望的那么聪明。 It just reruns when it detects changes.它只是在检测到更改时重新运行。

I know this is a 3-year-old question but I think it will help people who face the similar problem in future.我知道这是一个 3 年前的问题,但我认为它会帮助将来面临类似问题的人。 So I found out a way to enable SBT style auto test execution in IntelliJ studio.所以我找到了一种在 IntelliJ Studio 中启用 SBT 风格自动测试执行的方法。

We need to do 2 things to enable auto test execution.我们需要做两件事来启用自动测试执行。

  1. Enabling auto project build - This can be done in settings by going into File -> Settings -> Build, Execution... -> Compiler and selecting "Build Project automatically" .启用自动项目构建 - 这可以通过进入File -> Settings -> Build, Execution... -> Compiler并选择"Build Project automatically"在设置中完成。

在此处输入图片说明

  1. Enabling "Toggle auto-test" in run dialog box在运行对话框中启用“切换自动测试”

This will start auto testing.这将开始自动测试。 Although this works fine, it takes time to build the project even when my project is tiny so for larger projects it will certainly take very long time to complete the build and execute tests.虽然这工作正常,但即使我的项目很小,构建项目也需要时间,因此对于较大的项目,完成构建和执行测试肯定需要很长时间。

Reference: Original article which explains these steps参考: 解释这些步骤的原始文章

如果您可以运行涵盖您选择的单个方法的测试,则可以尝试此插件(从某种意义上说,它是连续的,您对方法进行更改,然后单击该方法,该插件将自动运行所有单元测试其中涵盖了该方法): https : //plugins.jetbrains.com/plugin/15063-unit-test-coverage-history-runner

You can use the Intellij Teamcity plugin.您可以使用Intellij Teamcity插件。 Teamcity is a paid product but there is a free version which gives you 20 projects and 3 agents for free . Teamcity 是付费产品,但有一个免费版本,可以免费为您提供 20 个项目和 3 个代理。

  1. It has a remote run feature using which you can send in unchecked code to run tests before committing.它具有远程运行功能,您可以使用该功能在提交之前发送未经检查的代码以运行测试。
  2. It also has options to run failed tests first它还可以选择先运行失败的测试

Usage instructions for Remote Run 远程运行使用说明

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

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