如何让TestNG在关闭测试之前等待我的测试完成 [英] How to make TestNG wait for my test to complete before shutting it down

查看:173
本文介绍了如何让TestNG在关闭测试之前等待我的测试完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试结构有点复杂,所以请耐心等待

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

我有一系列的testng测试用例,在每个测试用例中,我都会收集有关该测试的一些数据(不是直接而是使用我编写的库).该库一旦获取数据,就会在另一个线程上启动一个分析程序,而主线程将继续执行其余的测试. (我这样做是因为分析有些耗时,而且我不希望主要测试受阻).

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).

最后,仅剩下几个分析程序线程,但是testng仍然关闭了测试,并且无法分析最后几个测试用例的数据.

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.

我最后不想硬编码的睡眠.有没有一种方法可以指导TestNG等待该测试(直接或通过关联的库)产生的任何线程完成?

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?

推荐答案

通常,您可以执行以下操作之一:
1)通过使主线程使用来等待另一个线程

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

Thread.join();

2)将另一个线程设为非守护程序或用户线程:

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

Thread.setDaemon(false);

仅运行的所有线程都是守护程序线程时,Java虚拟机退出.必须在启动线程之前调用此方法.

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

这篇关于如何让TestNG在关闭测试之前等待我的测试完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆