TestNG多線程測試-注解方式實現


用@Test(invocationCount = x,threadPoolSize = y)聲明,
invocationCount表示執行次數,threadPoolSize表示線程池大小。
package com.janson.multiThread;

import org.testng.annotations.Test;

public class MultiThreadOnAnnotation {

    /**
     * 多線程測試,沒有關聯的用例可以使用多線程,減少執行時間
     * 以下演示3個線程同時運行,共執行10次
     */
    @Test(invocationCount = 10,threadPoolSize = 3)
    public void test() {
        System.out.println("*************hello world**************");
        System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
    }
}

運行結果:

*************hello world**************
*************hello world**************
Thread Id : 13
*************hello world**************
Thread Id : 12
Thread Id : 11
*************hello world**************
*************hello world**************
Thread Id : 11
Thread Id : 13
*************hello world**************
Thread Id : 12
*************hello world**************
Thread Id : 11
*************hello world**************
Thread Id : 13
*************hello world**************
*************hello world**************
Thread Id : 11
Thread Id : 12

===============================================
Default Suite
Total tests run: 10, Failures: 0, Skips: 0
===============================================


Process finished with exit code 0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM