简体   繁体   English

使用maven surefire插件运行多个测试类

[英]Running multiple test classes with maven surefire plugin

I'm trying to use the parallel option in the maven-surefire-plugin to run multiple test classes at once. 我正在尝试使用maven-surefire-plugin中的parallel选项一次运行多个测试类。 Below is my configuration: 以下是我的配置:

<configuration>
    <argLine>-Xmx1024m -XX:MaxPermSize=1024m</argLine>
    <excludes>
        <exclude>**/Test*.java</exclude>
    </excludes>
    <runOrder>hourly</runOrder>
    <parallel>classes</parallel>
    <threadCountClasses>5</threadCountClasses>
</configuration>

It very clearly is doing parallel test classes but it's doing far more than what I would expect. 很明显它正在进行并行测试,但它的功能远远超出我的预期。 I see it jumping up to approximately 40 test classes being executed at once, despite the threadCountClasses being set to 5. Am I misunderstanding how these options work? 尽管threadCountClasses设置为5,我看到它一下子跳到大约40个测试类,我误解了这些选项是如何工作的? My desire would be for only five test classes to be executing at any one time. 我的愿望是在任何时候只执行五个测试类。 As it is, it's choking my system with 40. 事实上,它让我的系统窒息了40。

I'm currently running version 2.17 of the plugin. 我目前正在运行该插件的2.17版本。

Edit : Is there any chance the number of CPU cores would come into play here? 编辑 :CPU内核的数量是否有可能在这里发挥作用? After more careful accounting, I realize I am running exactly 40 test classes with this configuration and I have 8 cores. 经过更仔细的计算,我意识到我正在运行这个配置的40个测试类,我有8个核心。 It seems like it would be quite a coincidence if the CPU cores don't play a part. 如果CPU核心没有发挥作用,这似乎是巧合。

As per official documentation on the threadCountClasses configuration entry 根据threadCountClasses配置条目的官方文档

This attribute allows you to specify the concurrency in test classes, ie: 此属性允许您指定测试类中的并发性,即:

  • number of concurrent classes if threadCount is 0 or unspecified 如果threadCount为0或未指定, threadCount并发类的数量
  • limited classes concurrency if useUnlimitedThreads is set to true 如果useUnlimitedThreads设置为true则限制类并发
  • if threadCount and certain thread-count parameters are > 0 for parallel, the concurrency is computed from ratio. 如果threadCount和某些线程计数参数对于并行是> 0,则并发性是根据比率计算的。 For instance parallel = all and the ratio between threadCountSuites : threadCountClasses : threadCountMethods is 2:3:5, there is 30% of threadCount in concurrent classes. 例如, parallel = allthreadCountSuitesthreadCountClassesthreadCountMethods之间的比例是2:3:5,并发类中有30%的threadCount。
  • as in the previous case but without this leaf thread-count. 与前一种情况一样,但没有这个叶子线程计数。 Example: parallel = suitesAndClasses , threadCount =16, threadCountSuites =5, threadCountClasses is unspecified leaf, the number of concurrent classes is varying from >= 11 to 14 or 15. The threadCountSuites become number of threads. 示例: parallel = suitesAndClassesthreadCount = 16, threadCountSuites = 5,threadCountClasses是未指定的叶,并发类的数量从> = 11到14或15 threadCountSuites变为线程数。

Only makes sense to use in conjunction with the parallel parameter. 只有与并行参数一起使用才有意义。 The default value 0 behaves same as unspecified one. 默认值0的行为与未指定的值相同。

In your case you are not specifying the threadCount element, hence you should fall into the first case (number of concurrent classes) which however it doesn't seem to be the case. 在你的情况下你没有指定threadCount元素,因此你应该属于第一种情况(并发类的数量),但是它似乎并非如此。

The third and fourth case instead define a ratio (and not a specific number), as it instead seems to happen in your case. 第三种情况和第四种情况相反定义了一个比率(而不是一个特定的数字),因为它似乎发生在你的情况下。 Ratio however depends on your test classes (suites, if any, classes and methods) and not on your CPU cores. 但是,比率取决于您的测试类(套件,如果有的话,类和方法),而不取决于您的CPU核心。

However, the perCoreThreadCount configuration entry: 但是, perCoreThreadCount配置条目:

Indicates that threadCount , threadCountSuites , threadCountClasses , threadCountMethods are per cpu core. 表示threadCountthreadCountSuitesthreadCountClassesthreadCountMethods是每个cpu核心。

Is set to true by default, effectively influencing the dynamics described above and matching the behavior you described (according to option one above). 默认设置为true ,有效地影响上述动态并匹配您描述的行为(根据上面的选项1)。

Hence, a suggestion would be to set it to false . 因此,建议将其设置为false

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

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