Reducing Code Redundancy Within Test Cases

Learn how to reduce test code redundancy within each test method.


Test methods often require testing the same behavior but with different inputs. NUnit supports parameterized tests to test the same behavior with a diverse array of input/output pairs. If a group of test cases is common enough, parameterization reduces the number of test methods. This reduces the developer’s workload.

Parameterizing tests

Suppose we have an application code that returns the type of triangle depending on triangle lengths. The Triangle class has a simple constructor and exposes the GetTriangleType method (line 21) to return the type of triangle. This code is shown below. Run the test cases to ensure all tests pass:

Get hands-on with 1200+ tech skills courses.