Use annotations for testng thread pool configuration, execution count configuration, timeout configuration
Note: Use annotations to control the number of times the test method runs and time out, timeout in single-threaded or multithreaded mode is available, ThreadPoolSize set the number of thread pool *, when observing the results, found that many values are duplicated, but may not be equal to the number of thread pool we configured, Because the number of threads also depends on the support of the hardware CPU,
Invocationcount----Indicates the number of executions
ThreadPoolSize-----Indicates the number of threads in the thread pool
Timeout-------time-out-milliseconds
Java Code:
[Java]View PlainCopy
- /**
- *
- * <p>
- * Title:testnginvocationcount
- * </p>
- *
- * <p>
- * Description:
- * Use annotations to control the number of times the test method runs and time out, timeout is available in single-threaded or multithreaded mode, ThreadPoolSize sets the number of thread pools
- *, when observing the results, we find that many values are duplicated, but may not be equal to the number of thread pool threads we configured, because the number also depends on the hardware CPU support.
- * </p>
- *
- * <p>
- * Company:
- * </p>
- *
- * @author: Dragon
- *
- * @date: October 22, 2014
- */
- Public class Testnginvocationcount {
- private static int sum = 0;
- @Test (ThreadPoolSize = 2, Invocationcount = ten, TimeOut = + )
- public void TestServer () throws interruptedexception {
- //detect the number of threads started, when the number of boot is more than the number of CPU cores, is actually re-scheduling
- //Thread.Sleep (2000);
- sum++;
- System.out.println ("..." + sum);
- }
- }
Test results:
[HTML]View PlainCopy
- [Threadutil] Starting executor timeout:1000ms workers:10 Threadpoolsize:3
- ......... 2
- ......... 2
- ......... 2
- ......... 3
- ......... 4
- ......... 5
- ......... 6
- ......... 7
- ......... 8
- ......... 9
- Passed:testserver
- Passed:testserver
- Passed:testserver
- Passed:testserver
- Passed:testserver
- Passed:testserver
- Passed:testserver
- Passed:testserver
- Passed:testserver
- PASSED: testserver
- ===============================================
- Default Test
- Tests run:10, failures:0, skips: 0
- ===============================================
testng thread pool configuration, execution count configuration, timeout configuration