TestNG parallel classesAndMethods without XML

只谈情不闲聊 提交于 2019-12-12 22:21:34

问题


I'm trying to have both classes and methods running in parallel.

For example:

Method Tests

public class MethodTests(){

    @Test(groups = "testMe")
    public void methodTestOne(){
    ...
    }

    @Test(groups = "testMe")
    public void methodTestTwo(){
    ...
    }

}

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(){
    ...
    }

}

I've included the surefire-plugin:

<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>

Note: I've also tried classesAndMethods

I'm running from the command line like this:

mvn clean verify -Dgroups=testMe -Dthreads=3

I'm trying to accomplish the classTests run on one thread, and the method tests use a different thread after being complete.

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.

I need both scenarios, and I do not want to use any XML.


回答1:


I am not sure I quite understand the use case. But the only combinations of parallelism supported by TestNG are as below

  • 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 parallel
  • methods - causes multiple @Test methods to run in parallel

I dont remember seeing something called all. I think that's applicable only to the JUnit provider for Maven surefire plugin. Please see here.

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.

The value that you should be using is classes, like this : <parallel>classes</parallel>



来源:https://stackoverflow.com/questions/41387080/testng-parallel-classesandmethods-without-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!