We've briefly covered the concept of object-orientation with regard to tests. We covered encapsulating context within a test class to be shared amongst test classes. But there's much more to object-oriented design that can be taken advantage of in automated tests.
Each test class is a test fixture. The name of the fixture can focus group a given set of tests. We've seen examples of test fixtures that share setup and how that setup would be extracted into a single method or into the constructor to stay DRY. This concept can be expanded to a subgroup related tests into multiple classes to gain extra clarity through the class name into a base fixture class. If we return to our Class1TestsB
example, let's say moving TestMethod1
and TestMethod2
into separate classes gives us the ability to subgroup these tests into an individual class with a more clear class name. We could pull up the setup and teardown into a new base class shown as follows:
[TestClass] public abstract...