VSoftTechnologies / DUnitX

Delphi Unit Test Framework
Apache License 2.0
381 stars 198 forks source link

Add a way to stop a runner gracefully #150

Open vincentparrett opened 8 years ago

vincentparrett commented 8 years ago

There is no way currently to interrupt the runner, it's in a tight loop and runs to completion.

rmcginty commented 7 years ago

@vincentparrett Do you have any ideas on where the best place to tie into this would be? Now that I you added the UI updating in real-time, and now that I have like over 1000 tests in some projects, I am increasingly finding myself wishing I could cancel an accidental "run all". I have not worked in the test engine itself hardly at all, so I was just curious if you could point me in a spot where you think this should go and I was going to look into getting it in there.

I would assume we start with some sort simple "stop run" flag somewhere that is checked before starting the next test (this is the spot I would need your opinion on), rather than a full up "abort running test" style thing for a rouge infinite loop or similar situation. For now, task manager works just fine for the latter :)

vincentparrett commented 7 years ago

I was thinking a simple Aborted property on the runner would deal with not running the next test, but the tests themselves do not have access to the runner or any sort of context. So for a running test to check for abort it would need to be a flag somewhere in the TestFramework unit, so perhaps a class property on TDUnitX that the runner checks and test implementers can check if doing long running loops etc. In console applications, adding a Ctrl+C handler would be needed (simple for windows using SetConsoleCtrlHandler, I have no idea how that would be done for other platforms), so would need to be added to the wizard generated code. Also, what should the exit code be if someone stops the tests? For the gui runner, you would just have to remember to reset it once the tests have stopped. We should probably ping @sglienke on this as I'm not sure if TestInsight has the ability to abort tests with DUnitX. I tried to test this, but my tests run too fast!

sglienke commented 7 years ago

TestInsight is able to terminate the tests via TerminateProcess on Windows (the stop button in its toolbar that enables when the tests are running) which works quite fine as it can also kill a test process that is not responding anymore. Helped me quite a few times when something went badly wrong somewhere.