Re: [testng-users] Abort Test Run Programmatically

1,358 views
Skip to first unread message

Cédric Beust ♔

unread,
Jun 15, 2012, 9:01:03 PM6/15/12
to testng...@googlegroups.com
Hi,

If you launch the TestNG runner in single threaded more, killing the thread should definitely work, can you explain in details what you tried to do?

At a more general level, the only safe way to do this is to launch TestNG in a separate process and communicate with the remote process via sockets. Then you can implement a "stop" message in your protocol. That's how all the TestNG runners in IDE's (Eclipse and IDEA) are implemented.

Take a look at RemoteTestNG to get a feel for how this works and read the file README.dev in the root of the TestNG repository.

-- 
Cédric




On Mon, Jun 11, 2012 at 8:44 AM, Lostprophet <ronny...@googlemail.com> wrote:
Hi, 

I've written a runner for TestNG (I wrote it for JUnit originally, but I'm changing the implementation towards TestNG at the moment) that provides a simple to use Graphical User Interface. 
I launch TestNG on a virtual xml-file via the TestNG.run()-method. In case the user of my runner wants to abort the current test run, I implemented a Stop-button. 

My question is, how can I abort such a test run? I really have no idea and the TestNG-class doesn't seem to include a method for that purpose.

On a strange side note, aborting a run in JUnit wasn't that hard. At least I could always fall back to simply killing its thread. However, TestNG is almost completely unaffected if I kill its thread (with the deprecated Thread.stop()-method), it just keeps running the tests.


Can anybody please help me out? That simple and fundamental functionality is driving me to despair...


Best Regards, Lostprophet

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/OIaxprKhCtMJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Lostprophet

unread,
Jun 18, 2012, 11:05:26 AM6/18/12
to testng...@googlegroups.com
Hi,

thanks for the reply! I stumbled over the source code of the eclipse plugin in the meantime myself, but for someone who has never worked with processes, it is pretty hard to understand the inner workings. But anyway, that is my own problem I guess.

As for the thread-killing: I have a "GUI" class which declares a thread called "processorThread". The run()-method of that thread only calls the run()-method of another class of mine, the "TestcaseProcessor" (responsible for the execution of tests). Now, within that run()-method of the "TestcaseProcessor" I build the virtual xml-suites and then do this:

TestNG tng = new TestNG();
tng.setXmlSuites(mySuites);
tng.addListener(this);
tng.run();

If one clicks the stop-button of my "GUI" while TestNG runs, I do this:

processorThread.stop();

I know that's not very elegant, but it worked with JUnit. If you clicked the stop-button while JUnit was running "simpleTest3" for example, then "simpleTest3" would fail with a "ThreadDeath" and no other test would be run after that. If I try the same with TestNG however, "simpleTest3" does fail because of a "ThreadDeath" (mostly, not always), but TestNG simply doesn't stop there. It continues executing "simpleTest4", "simpleTest5" etc.. 

Am I making a mistake here? Is that the single threaded mode I use? I'm not sure anymore, I also tried calling TestNG.setThreadCount(1) and TestNG.setSuiteThreadPoolSize(1) manually, but nothing changes.

I will take a look at RemoteTestNG and work that out if I have to, but I would prefer a simple solution like the one I tried to realize.


Best Regards, Lostprophet
Reply all
Reply to author
Forward
0 new messages