Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

java - How to make TestNG wait for my test to complete before shutting it down

I have a slightly complicated test structure so bear with me,

I have a series of testng test cases and during each I collect some data about the test( not directly but using a library which I wrote). This library once it gets the data kicks off an analysis program on another thread and the main thread proceeds with executing the rest of the test. (I do this because the analysis is slightly time consuming and I don't want the main test to block).

At the end only a few analysis program threads are left but testng still shuts the test down and the data for the last few test cases could not be analysed.

I don't want a hardcoded sleep at the end. Is there a way I can direct TestNG to wait until any threads spawned by this test (directly or via associated libraries) finish?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can in general do one of the following:
1) By making the main Thread wait for another Thread using

Thread.join();

2) Making the another Thread as Non Daemon or a user thread:link

Thread.setDaemon(false);

The Java Virtual Machine exits when the only threads running are all daemon threads.This method must be called before the thread is started.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...