Unit Testing with JUnit
No -- that's not a typo: "JUnit" (not NUnit). At my current job (which is usually VB6/SQL/Oracle development) I've had to do some Java coding. For someone familiar with .NET, it's not too bad.
I've recently become a big fan of NUnit, the free unit testing framework for .NET. It's a port of JUnit, designed for Java. Since I used NUnit first and have recently been doing some test cases with JUnit, I've come to appreciate even more the power that .NET brings to developers. The attribute based approach in NUnit 2.0 is simply cleaner. For example:- ExpectedException attribute. With NUnit, simply decorate your test case with this attribute to specifiy an exception you expect to receive. In JUnit, you need to wrap your code in a try/catch block and simply ignore the expected exception (don't re-raise it). With no exception, the JUnit test case will pass. Messy...
- Ignore Attribute: A handy attribute that allows you to skip an NUnit test case. If using the GUI test runner, these test cases get flagged with yellow. For JUnit, there is no such thing -- it's pass or fail. However, I did a Google search and this is something that's been talked about, but it would be a special runner -- not part of the base JUnit code.
- Test and TestFixture attributes: These attributes mark your test cases. In JUnit you have to prefix the method name with "test". Nuff said.