By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,865 Members | 1,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,865 IT Pros & Developers. It's quick & easy.

NUnit testing of eventlog entry?

P: n/a
Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my already
existing NUnit tests - but I'm a little low on ideas as how to assert that I
actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ole,
Naturally I want this assertion without having to open my eventlog and
visually verify the writing. Have you considered using a snippet of C# code (within the unit test itself)
to "open" the eventlog & "read" the entries to see if the entry you expect
was written?

You can use the EventLog.Entries property to "read" the entries from an
EventLog...

http://msdn.microsoft.com/library/de...triesTopic.asp

Alternatively you might be able to use the EventWritten event to see if an
entry was written during the test...

If possible I would attempt to use a private test Event Log above so as to
have total control on outside programs interferring with the test...

Hope this helps
Jay
"Ole Hanson" <no@spam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl... Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my
already existing NUnit tests - but I'm a little low on ideas as how to
assert that I actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!

Nov 16 '05 #2

P: n/a
nUnit rides along with exceptions from the .NET framework and you may be
able to assert your test on an event log exception. A handled exception by
your code would by default cause nUnit to fail an assertion test unless you
override it with an ExpectedException parameter in your test method.

You could also use a conditional assertion in nUnit to check the return
value of the write method in your logging classes, that way you could at
least evaluate against a succesful write. NUnit also recognizes unhandled
exceptions as an indicator that the code has failed in some way. As such, it
reports unhandled exceptions as failures of any test itself - you could
likely assume that any other result permutation is a success without having
to actually open the event log

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Ole Hanson" <no@spam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my already existing NUnit tests - but I'm a little low on ideas as how to assert that I actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!

Nov 16 '05 #3

P: n/a
Great stuff!

Just what I needed.
Thanks

/Ole
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
Ole,
Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Have you considered using a snippet of C# code (within the unit test
itself) to "open" the eventlog & "read" the entries to see if the entry
you expect was written?

You can use the EventLog.Entries property to "read" the entries from an
EventLog...

http://msdn.microsoft.com/library/de...triesTopic.asp

Alternatively you might be able to use the EventWritten event to see if an
entry was written during the test...

If possible I would attempt to use a private test Event Log above so as to
have total control on outside programs interferring with the test...

Hope this helps
Jay
"Ole Hanson" <no@spam.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Hi

I am trying to engineer a way of testing that my logging framework is
capable of writing to my eventlog. I want to include this test in my
already existing NUnit tests - but I'm a little low on ideas as how to
assert that I actually did write to the eventlog successfully.

Naturally I want this assertion without having to open my eventlog and
visually verify the writing.

Any ideas???

Thanks!


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.