Running single test class or group with Surefire and TestNG

前端 未结 4 2033
忘了有多久
忘了有多久 2021-02-14 09:10

I want to run single test class from command line using Maven and TestNG

Things that doesn\'t work:

mvn -Dtest=ClassName test

I have de

4条回答
  •  天命终不由人
    2021-02-14 09:46

    I didn't test with TestNG 5.12.1 but I can say that running a single test using the test parameter and tests from groups using the groups parameter works with TestNG 5.14.2 (and surefire 2.6) (groups doesn't work in TestNG 5.14)

    Here is the pom.xml I'm using:

    
    
      4.0.0
      com.stackoverflow
      Q4159948
      1.0-SNAPSHOT
      Q4159948
      http://maven.apache.org
      
        1.6
        1.6
      
      
        
          org.testng
          testng
          5.14.2
          test
        
      
      
        
          
            org.apache.maven.plugins
            maven-surefire-plugin
            2.6
            
          
        
      
    
    

    With a simple AppTest as follow:

    import org.testng.annotations.*;
    
    public class AppTest {
    
     @BeforeClass
     public void setUp() {
       // code that will be invoked when this test is instantiated
     }
    
     @Test(groups = { "fast" })
     public void aFastTest() {
       System.out.println("Fast test");
     }
    
     @Test(groups = { "slow" })
     public void aSlowTest() {
        System.out.println("Slow test");
     }
    
    }
    

    Both

    $ mvn test -Dtest=AppTest
    

    and

    $ mvn test -Dgroups=slow
    

    produce the expected result.

提交回复
热议问题