Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 292
Srini Avatar asked Jan 01 '26 02:01

Srini


1 Answers

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.

like image 84
Kedar Parikh Avatar answered Jan 03 '26 14:01

Kedar Parikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!