没有XML的TestNG并行classesAndMethods [英] TestNG parallel classesAndMethods without XML
问题描述
我正在尝试同时运行类和方法.
I'm trying to have both classes and methods running in parallel.
例如:
方法测试
public class MethodTests(){
@Test(groups = "testMe")
public void methodTestOne(){
...
}
@Test(groups = "testMe")
public void methodTestTwo(){
...
}
}
课堂测试->希望在班级上使用Test注释
Class Tests -> Hoping the Test annotation on the class level would do it
@Test
public class ClassTests(){
@Test(groups = "testMe")
public void classTestOne(){
...
}
@Test(groups = "testMe")
public void classTestTwo(){
...
}
}
我包含了surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<parallel>all</parallel>
<threadCount>${threads}</threadCount>
...
</plugin>
注意:我也尝试过 classesAndMethods
我从这样的命令行运行:
I'm running from the command line like this:
mvn clean verify -Dgroups=testMe -Dthreads=3
我试图完成在一个线程上运行的classTests,并且方法测试完成后使用另一个线程.
I'm trying to accomplish the classTests run on one thread, and the method tests use a different thread after being complete.
目的:在beforeClass中,我要设置测试,然后快速在页面上声明多个内容,如果失败,则希望它仍然测试页面上的其他内容.
Purpose: In the beforeClass, I'm setting up the test, and then quickly asserting multiple things on a page, If one fails, I want it to still test the other things on the page.
如果方法测试失败,则需要它完全停止.
Where as, if the method tests fail, I need it to completely stop.
我需要这两种情况,并且我不想使用任何XML.
I need both scenarios, and I do not want to use any XML.
推荐答案
我不确定我是否完全理解用例.但是TestNG支持的并行性的唯一组合如下
I am not sure I quite understand the use case. But the only combinations of parallelism supported by TestNG are as below
-
tests
-使标签内的@Test方法并行运行. -
instances
-导致测试类实例中的@Test方法并行运行. -
classes
-使测试类并行运行 -
方法
-导致多个@Test方法并行运行
tests
- causes @Test methods inside tags to run in parallel.instances
- Causes @Test methods inside test class instances to run in parallel.classes
- causes test classes to run in parallelmethods
- causes multiple @Test methods to run in parallel
我不记得看到什么叫做 all
的东西.我认为这仅适用于Maven surefire插件的JUnit提供程序.请在此处.
I dont remember seeing something called all
. I think that's applicable only to the JUnit provider for Maven surefire plugin. Please see here.
对于您的方案,只要拥有 @BeforeClass(alwaysRun = true)
,它将对所有 groups
执行,并且将防止依赖于测试方法跳过之前的课程.
For your scenario as long as you have the @BeforeClass(alwaysRun=true)
it would be executed for all groups
and it would prevent the test methods that are dependent on the before class to be skipped.
您应该使用的值是 classes
,例如:< parallel> classes</parallel>
The value that you should be using is classes
, like this : <parallel>classes</parallel>
这篇关于没有XML的TestNG并行classesAndMethods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!