Parameterized Unit Tests with JUnit
I’ve been shown a lovely little utility for testing with JUnit 4.11 whereby one can have a list of items performed as part of the single unit test.
First add the annotations you see below and set your inputs and expected outputs. (Arrange and Assert)
![]()
Then create a constructor and some static variables to store each Tuple.
![]()
Then define your single unit test (the business logic is your Action).
![]()
That’s it, a really nice way to have a single unit test that can be run multiple times with different parameters.
![]()
If you would like to do the same sort of testing in .NET you have some choices to make.
You could use NUnit and use the TestCaseAttribute.
![]()
Or if like me you prefer MSTest then you can opt for a data driven unit test.
See this vs2013 page (has worked at least since vs2010):
http://msdn.microsoft.com/en-US/library/ms182527(v=vs.120)
![]()