NUnit Testing

P

Patrick

Has anyone had much experience with NUnit http://www.nunit.org , an open
source Unit Testing tool?

If so, has anyone had experience of how to test a method that returns VOID?
None of the ovedloaded Assert.IsNull or Assert.AreEqual methods seem
suitable!

(although I could argue that the methods to be tested should return true)
 
P

Patrick

Also, when you do a System.Diagnostics.Trace.WriteLine, the line is not
written to the NUnit GUI's console.Out tab
 
G

Guest

Hi Patrick. Typically a method that returns void must be somehow changing
the state of an object or group of objects. Othewise, it's not doing
anything.

The typical way to unit test a method such as this is to create an instance
of the object in a known state and then call the method and Assert that the
appropriate changes take place.

If the method takes in an instance of some class as a parameter and modifies
that instance, another option is to check the state of the instance after
passing it to the method.

Some people are fans of interaction testing using mock objects (such as
http://www.nmock.org/). In this scenario, you pass in a mock object to the
method instead of the actual object. THe mock object asserts that the
interaction with it is correct. (If that last bit doesn't make sense, check
out the nmock site for more details).
 
P

Patrick

Well, this method that returns void (currently) is a web-service proxy
client class (generated by WSDL.exe).
 
J

Jay B. Harlow [MVP - Outlook]

Patrick,
In addition to the other comments:

James W. Newkirk's & Alexei A. Vorontsov's book "Test-Driven Development in
Microsoft .NET" from MS Press provides a plethora of information on using
NUnit to test .NET projects, including web services & methods that return
void.

I'm about half way thru it, I would recommend this book for anyone doing TDD
(.NET or Java).

Hope this helps
Jay
 
P

Patrick

Without going into the trouble of getting hold of this book, could you share
with me what is the "key" to testing void methods or web-services?
 
J

Jay B. Harlow [MVP - Outlook]

Patrick,
Basically what Haacked stated.

There is an entire chapter on testing web-services, so I really don't think
I can paraphrase it any simpler then what Haacked stated...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top