标题翻译
FitNesse with JUnit : Execute suites in parallel
问题
我有两个互斥的FitNesse套件,我想要并行运行它们。
由于它们是从`junit`测试用例中调用的,我编写了以下代码:
@Test
public void executeFitnesseSuites() {
final Class<?>[] classes = { Suite1.class, Suite2.class };
final Result result = JUnitCore.runClasses(ParallelComputer.classes(), classes);
System.out.println(result);
}
@RunWith(FitNesseRunner.class)
@FitNesseRunner.Suite("Suite1")
@FitNesseRunner.FitnesseDir(".")
@FitNesseRunner.OutputDir("/tmp/fitnesse/")
public static class Suite1 {
}
@RunWith(FitNesseRunner.class)
@FitNesseRunner.Suite("Suite2")
@FitNesseRunner.FitnesseDir(".")
@FitNesseRunner.OutputDir("/tmp/fitnesse/")
public static class Suite2 {
}
在早期的实现中,这些是两个独立的类,按顺序执行。
然而,我看到上述测试的执行时间相似。
这是否意味着FitNesse没有启动两个Slim服务器实例,并在并行中执行这些套件?
<details>
<summary>英文翻译</summary>
I have two FitNesse suits which are mutually exclusive and I want to run them in parallel.
As they are invoked from a `junit` test case, I have written the following piece of code:
@Test
public void executeFitnesseSuites() {
final Class<?>[] classes = { Suite1.class, Suite2.class };
final Result result = JUnitCore.runClasses(ParallelComputer.classes(), classes);
System.out.println(result);
}
@RunWith(FitNesseRunner.class)
@FitNesseRunner.Suite("Suite1")
@FitNesseRunner.FitnesseDir(".")
@FitNesseRunner.OutputDir("/tmp/fitnesse/")
public static class Suite1{
}
@RunWith(FitNesseRunner.class)
@FitNesseRunner.Suite("Suite2")
@FitNesseRunner.FitnesseDir(".")
@FitNesseRunner.OutputDir("/tmp/fitnesse/")
public static class Suite2{
}
In the earlier implementation, these were two independent classes and were being executed sequentially.
However, I am seeing a similar execution time for the above test.
Does this mean that FitNesse is not spinning up two slim server instances and executing these suites in parallel?
</details>
# 答案1
**得分**: 0
很遗憾,FitNesse本身不是线程安全的,因此不应该在同一个JVM中同时运行两个slim服务器实例。
关于您使用的方法,我不确定jUnit的行为。它是在两个并行的JVM中运行,还是在同一个JVM中的不同线程中运行?
我过去使用过的一种方法是在jUnit中运行两个完全独立的测试套件,可以使用两个单独的类(就像您之前做的那样),然后使用Maven的failsafe插件在单独的JVM中并行运行它们。Failsafe(以及surefire)提供了`forkCount`属性,用于指定要使用的进程数(详见http://maven.apache.org/surefire/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html 获取更多详情)。***请注意***,不要使用`parallel`属性,因为那是在一个JVM内部。
如果您正在使用FitNesse的jUnit运行器并行运行测试,您可能还会对我创建的一个工具感兴趣,该工具可以将这些运行的HTML报告合并成一个报告:[HtmlReportIndexGenerator][1]。这是我的fixtures jar的一部分,但也可以作为单独的[docker镜像提供:hsac/fitnesse-fixtures-combine][2]。
[1]: https://github.com/fhoeben/hsac-fitnesse-fixtures/blob/master/src/main/java/nl/hsac/fitnesse/junit/reportmerge/HtmlReportIndexGenerator.java
[2]: https://hub.docker.com/r/hsac/fitnesse-fixtures-combine
<details>
<summary>英文翻译</summary>
Unfortunately FitNesse itself is not thread safe, so one should not run two slim server instances in one JVM at the same time.
I'm not sure how jUnit behaves using the approach you use. Does it spin up two parallel JVMs, or just threads in the same JVM?
An approach I've used in the past to run two completely independent suites with jUnit is two have two separate classes (as you had before) and run these in parallel on separate JVMs using Maven's failsafe plugin. Failsafe (and surefire as well) offers a `forkCount` property to specify the number of processes to use (see http://maven.apache.org/surefire/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html for more details). ***Please note*** that you should NOT use the `parallel` property as that is within one JVM.
If you are running tests in parallel using FitNesse's jUnit runner you may also be interested in a tool I created to combine the HTML reports of such runs into a single report: [HtmlReportIndexGenerator][1]. This is part my fixtures jar, but also available as separate [docker image: hsac/fitnesse-fixtures-combine][2].
[1]: https://github.com/fhoeben/hsac-fitnesse-fixtures/blob/master/src/main/java/nl/hsac/fitnesse/junit/reportmerge/HtmlReportIndexGenerator.java
[2]: https://hub.docker.com/r/hsac/fitnesse-fixtures-combine
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论