When a lot of people start unit testing, they seem to think that because the code isn't 'production' code that the unit test code doesn't really matter that much and that they can hack together something quick and dirty and it doesn't matter.

Generally, what happens when people take this approach, is that after a few months, maintaining and keeping the tests working becomes a nightmare and people either give up writing and maintaining the tests and consider writing unit tests as a waste of time, or, they have to spend several weeks sorting the code out.

My warning to you is that it's worth spending a little bit of effort up-front writing good code, as it will make your life much simpler and easier in the long run.

One big pain point around tests is duplicate code. Like all good code, you should follow the DRY principle when you write tests. If you refactor some code and then 15 different tests break, it's annoying having to go everywhere and fix it. If you can follow the DRY principle when you write your tests, maintenance will become a lot more pleasurable experience.

One way of sticking to the DRY principle is bypassing in parameters to your NUnit tests instead of duplicating the tests, for example, imagine this test:

This is a very basic example, but, if you had to update CallMethod() you have two tests to fix. When we use NUnit we can pass parameters into tests, so the above test can also be written like this:

This makes our unit test code a lot simpler. If you make a change, you only have to change one test instead of two. In more complex scenarios you may pass 5-10 parameters into a test. Following this approach will make your codebase more robust, so I suggest you start using it now.

How To Pass Objects Into Unit Tests

The above code works well for the standard out of the box data-types, but if you try and instantiate a new object as an input parameter, Visual Studio will be quick to point out that you can't do that.  Fear not, NUnit provides another way to pass parameters into your tests, like so:

NUnit Takeaway

As you can see, passing in parameters into your tests is pretty easy and it will drastically reduce the amount of duplicate NUnit test code that you'll need to write.