Reducing Code Redundancy Using Many Test Fixtures
Explore how to reduce redundancy in unit tests by using NUnit's TestFixture attribute to parameterize setup methods. Learn to manage multiple test fixtures for diverse data arrangements, improving test maintainability and efficiency while understanding when to use conditional logic.
Introduction
Test code redundancy is reduced by using the setup method and test method parameterization. The NUnit Setup attribute helps arrange data consistently across unit tests. When two or more unit tests need to arrange the same data, we may use a Setup method for this purpose. The Setup method is called before each test method is run. This helps avoid test code duplication. The NUnit TestCase attribute helps parameterize your test case input and expected data for a single test method.
This lesson details the TestFixture technique that may further reduce test code redundancy. The TestCase attribute parameterizes test methods, and the TestFixture attribute parameterizes the setup method.
The TestFixture attribute
Unit tests are typically expressed in NUnit as test methods. Test methods are methods decorated with the Test attribute. Since NUnit is a ...