2

我正在尝试通过 Java 应用程序而不是在 UI 上执行我的 SOAPUI 测试套件。但是,当创建一个 WSDLProject 时,一个线程正在启​​动并且永远不会被杀死,所以当我的代码被执行并且所有的测试都运行时,应用程序并没有结束,因为这个线程仍然在那里。

它看起来像一个 AWT 守护线程

在 Eclipse 调试器中:

Daemon Thread [AWT-Windows] (Running)   

这是我的代码:

WsdlProject projectName = String.format(
    "src/main/resources/%s-soapui-project.xml", projectName);
WsdlProject project = new WsdlProject(projectName); //This line starts the thread

List<TestSuite> testSuites = project.getTestSuiteList();

//Loop over each testsuite
    //Loop over each test case

有谁知道如何杀死这个线程?

我搜索并搜索了 SOAPUI API,但文档很糟糕,我找不到任何体面的例子来说明如何解决这个问题。

4

2 回答 2

5

For the past two days I have been struggling with the same problem. I have a solution which may help. The reason your does not end is not the AWT-Windows thread. The culprit is the thread labeled "Thread-2" which is of type SoapUIMultiThreadedHttpConnectionManager.IdleConnectionMonitorThread

Unfortunately this thread which is created when you instantiate WsdlProject, has no directly accessible shutdown method. This is what I had to do in-order to shut it down and have the JVM exit when my main routine exits:

Have your main method or some other method execute the following at the end:

// Need to shutdown all the threads invoked by each SoapUI TestSuite
SoapUI.getThreadPool().shutdown();
try {
        SoapUI.getThreadPool().awaitTermination(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
        e.printStackTrace();
}

// Now to shutdown the monitor thread setup by SoapUI
Thread[] tarray = new Thread[Thread.activeCount()];
Thread.enumerate(tarray);
for (Thread t : tarray) {
        if (t instanceof SoapUIMultiThreadedHttpConnectionManager.IdleConnectionMonitorThread) {
                ((SoapUIMultiThreadedHttpConnectionManager.IdleConnectionMonitorThread) t)
                .shutdown();
        }
}

// Finally Shutdown SoapUI itself.
SoapUI.shutdown();

Although ugly, I hope this solution helps you.

于 2014-08-06T14:01:14.767 回答
1

我已经用以下解决方案解决了这个问题。这并不理想,但我找不到解决方法,而且 SOAP UI 文档非常痛苦。

首先,我将每个测试步骤的结果保存到一个 xml 文件中。

接下来,一旦测试运行我退出:

System.exit(runner.getOverallResult() ? 0 : 1);

最后,另一个应用程序通过命令行 .sh 脚本执行此操作。执行后,其他应用程序读取 XML 文件以确定结果。

于 2013-02-25T12:30:48.300 回答