how to run one or group of tests repeatedly in Go Test IntelliJ

huangapple go评论83阅读模式
英文:

how to run one or group of tests repeatedly in Go Test IntelliJ

问题

我时不时会遇到这种令人讨厌的测试,其中存在间歇性问题,我需要运行多次才能暴露出来。我正在寻找一种方便的方法,可以从IntelliJ设置一个数字或者"无限循环",但我没有找到。

是否有插件或者我错过了某些东西,可以允许我从UI界面上进行设置(而不是修改代码)。

编辑:我发现这种功能的支持是基于测试工具插件的。例如,JUnit已经存在这样的功能,但Go Test没有。我的直觉告诉我,这种功能应该为所有测试插件通用提供,但可能有一些技术上的原因导致采用了每个插件的方法。

英文:

From time to time I have this annoying tests with intermittent issues, that I need to run many times to expose. I was looking for a convenient way to set a number or "endless loop" from the intelliJ, but I did not find.

Is there a plugin or I missed something that could allow me to do this from the UI (instead of changing code for it).

EDIT: As I found the support for such feature is per test utility plugin. For example, it already exists for JUnit, but there is no such for Go Test. My instinct suggests that such functionality should be generically provided for all test plugins, but there might be some technical reasons for per plugin approach.

答案1

得分: 20

在测试的运行配置中,有一个名为"Repeat:"的下拉菜单,您可以在其中指定重复的次数,例如直到测试失败。我相信这个功能从IntelliJ IDEA 15开始就可用了。

英文:

In the Run Configuration of the test there is a "Repeat:" dropdown where you can specify the number of repeats, for example until the test fails. I believe this is available since IntelliJ IDEA 15.

答案2

得分: 0

你可以使用Oracle JDK来创建一个执行器服务,该服务可以定期调度测试套件的运行/执行,除非你关闭该服务。

请参考以下Oracle文档:

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html

示例代码如下:

import static java.util.concurrent.TimeUnit.*;
class BeeperControl {
  private final ScheduledExecutorService scheduler =
    Executors.newScheduledThreadPool(1);

  public void beepForAnHour() {
    final Runnable beeper = new Runnable() {
      public void run() { System.out.println("beep"); }
    };
    final ScheduledFuture<?> beeperHandle =
      scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
    scheduler.schedule(new Runnable() {
      public void run() { beeperHandle.cancel(true); }
    }, 60 * 60, SECONDS);
  }
}
英文:
You can use oracle JDK to create a executor service which schedules the running /execution of the test suite periodically unless you shut down the service 

Please have a look at the below oracle doc 

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html

Sample 

 import static java.util.concurrent.TimeUnit.*;
 class BeeperControl {
   private final ScheduledExecutorService scheduler =
     Executors.newScheduledThreadPool(1);

   public void beepForAnHour() {
     final Runnable beeper = new Runnable() {
       public void run() { System.out.println(&quot;beep&quot;); }
     };
     final ScheduledFuture&lt;?&gt; beeperHandle =
       scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
     scheduler.schedule(new Runnable() {
       public void run() { beeperHandle.cancel(true); }
     }, 60 * 60, SECONDS);
   }
 }

huangapple
  • 本文由 发表于 2016年9月9日 00:34:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/39396165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定