代码如下:

package com.course.testng.multiThread;

import org.testng.annotations.Test;

public class MultiThreadOnXml {

    @Test
    public void test1(){
        System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
    }

    @Test
    public void test2(){
        System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
    }

    @Test
    public void test3(){
        System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
    }

}

resources下的xml文件:multiThread.xml

<?xml version="1.0" encoding="UTF-8" ?>

<suite name="thread" parallel="methods" thread-count="2">
    <!--
    methods级别:所有用例都可以在不同的线程下去执行
    tests级别:不同的test tag下的用例可以在不用的线程下去执行
              同一个tag的用例只能在同一个线程中去执行
    thread-count:代表了最大并发线程数
    xml文件配置这种方式不能制定线程池,只有方法上才可以指定线程池

    -->
    <test name="demo1">
        <classes>
            <class name="com.course.testng.multiThread.MultiThreadOnXml"/>

        </classes>

    </test>

</suite>

结果:

TestNg 10. 多线程测试-xml文件实现

 

相关文章:

  • 2021-07-27
  • 2022-02-03
  • 2022-12-23
  • 2021-12-23
  • 2021-09-09
  • 2021-12-06
  • 2022-02-06
猜你喜欢
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2022-03-04
  • 2021-12-03
  • 2021-05-18
  • 2021-06-04
相关资源
相似解决方案