TestNG·并行执行测试用例

前言

当测试用例都是独立的,用例之间不存在依赖时,我们可以进行并行设置,并行执行测试用例。

并行用例执行的维度有哪些?

本文将介绍通过TestNG并行执行case的相关知识点

正文

1、创建两个测试类 TestNGParallel1.java和TestNGParallel2.java

TestNGParallel1.java

public class TestNGParallel1 {
    @Test
    public void testMethod1() throws InterruptedException{
        System.out.println("TestNGParallel1类中的testMethod1方法");
        Thread.sleep(6000);
        System.out.println("TestNGParallel1类中的testMethod1方法中的更多执行步骤");
    }
    @Test
    public void testMethod2() throws InterruptedException{
        System.out.println("TestNGParallel1类中的testMethod2方法");
        Thread.sleep(6000);
        System.out.println("TestNGParallel1类中的testMethod2方法中的更多执行步骤");
    }
}

TestNGParallel2.java

public class TestNGParallel2 {
    @Test
    public void testMethod1() throws InterruptedException{
        System.out.println("TestNGParallel2类中的testMethod1方法");
        Thread.sleep(6000);
        System.out.println("TestNGParallel2类中的testMethod1方法中的更多执行步骤");
    }
    @Test
    public void testMethod2() throws InterruptedException{
        System.out.println("TestNGParallel2类中的testMethod2方法");
        Thread.sleep(6000);
        System.out.println("TestNGParallel2类中的testMethod2方法中的更多执行步骤");
    }
}

2、创建xml文件来进行管理。testngparallel.xml



    
        
            
        
    
    
        
            
        
    

创建两个标签来进行两个测试类的管理,

标签加上属性parallel属性thread-count

parallel属性的值是“tests”,表示该并行是在标签维度来并行执行的。

另外parallel属性的值还可以是"classes"和"methods",代表着并行执行classes和并行执行methods。

 

三人行,必有我师焉

你可能感兴趣的:(TestNG)