Is there a way to get notified whenever a test fails ?

39 views
Skip to first unread message

Gishu Pillai

unread,
May 19, 2012, 11:32:12 PM5/19/12
to nunit-...@googlegroups.com
Context:
I got some NUnit driven system tests - so the tests are slow, deals with moody HW etc. etc.

So the idea is to take a snapshot of the screen whenever the test fails for whatever reason. e.g. an unexpected error occurs

A colleague tried the EventListener interface mentioned in the NUnit Extensibility section of the docs.
void TestFinished(TestResult result);

However the event handler was only called once the test had failed AND the Teardown method was called. As a result, the screenshot doesn't have the requisite info e.g. teardown reboots the app. Is there a event that is fired synchronously and immediately when a test/assert fails.

Is there any way to make this work?
Gishu

Charlie Poole

unread,
May 20, 2012, 12:49:00 AM5/20/12
to nunit-...@googlegroups.com
There is no extension point to handle events occuring within the
execution of the test - and setup/teardown are treated as integral to
the test. It seems as if that could be useful. Can you file a 3.0
feature request so we remember?

As a workaround, you may consider putting the code in the teardown
itself, using the result from the TestContext to determine whether a
failure occured.

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

Gishu Pillai

unread,
May 20, 2012, 1:00:30 PM5/20/12
to nunit-...@googlegroups.com
Filed feature request #1001994

I ended up writing an Action attribute to do the same. It is called before the Teardown method. So now only the test methods need to be decorated with this attribute.
Someone can easily miss adding the screencapture call as the first thing in Teardown . Thanks for the suggestion.

Gishu

Charlie Poole

unread,
May 20, 2012, 4:02:41 PM5/20/12
to nunit-...@googlegroups.com
Good idea! It's new enough that I didn't think of it myself.

Charlie

Nicholas Bronson

unread,
May 21, 2012, 1:07:03 AM5/21/12
to nunit-...@googlegroups.com
This is a very interesting idea.  What sort of information are you trying to get from the screencap?  More than just the error messages?
Nicholas Bronson
(Bachelor of Computing, Master of Systems Development, MCPD: Enterprise Apps, MCTS: Sql Server 2005)
Microsoft Architect
Eclipse AD
Visit me at http://frater.wordpress.com

Gishu Pillai

unread,
May 21, 2012, 6:38:39 AM5/21/12
to nunit-...@googlegroups.com


On Mon, May 21, 2012 at 10:37 AM, Nicholas Bronson <nick.b...@gmail.com> wrote:
This is a very interesting idea.  What sort of information are you trying to get from the screencap?  More than just the error messages?

Well basically anything that'll give a clue as to why the test failed.

The system tests fail sometimes due to intermittent issues such as maybe the network tripped. This will pop up an unexpected error dialog or maybe cause a visual status change - leading to test failure. This change isn't likely enough (e.g. 5% case) for automation to account for it. Looking at a screenshot *may* save the time it takes to re run the test with a debugger attached, which could be minutes for a system test.
Having a human look at the application UI state may help solve problems faster.

Reply all
Reply to author
Forward
0 new messages