NUnit Testing

  • Thread starter Thread starter Patrick
  • Start date Start date
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)
 
Also, when you do a System.Diagnostics.Trace.WriteLine, the line is not
written to the NUnit GUI's console.Out tab
 
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).
 
Well, this method that returns void (currently) is a web-service proxy
client class (generated by WSDL.exe).
 
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
 
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?
 
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
 
Back
Top