When developing unit tests in Visual Studio, you often want to create some kind of base class for testing basic loniki. For example, we have the following class: [TestClass] public virtual class PersonTestBase {[TestClass] public virtual class PersonTestBase { [TestMethod] public void GetNameTest () { // ... } } and its heir class: [TestClass] public class CustomerTest: PersonTestBase { [TestMethod] public override void GetNameTest() { base.GetNameTest(); } }[TestClass] public class CustomerTest: PersonTestBase { [TestMethod] public override void GetNameTest() { base.GetNameTest(); } } Advantages of this approach:
full support for visual tools Visual Studio (Test List Editor);
ease of implementation.
Minuses:
code redundancy;
creating an heir is essentially copy & paste.
Immediately it should be noted that PersonTestBase and CustomerTest must be in the same assembly, otherwise tests in PersonTestBase will not work - this is a limitation of unit tests. See msdn for details. In addition to the methods described in msdn, you can do this: two projects are created: BaseTests and CustomTests; the necessary files from BaseTests are added to the CustomTests project in the following way: Project -> Add Existing Item -> Select the necessary files -> Add As Link. in different projects, but when compiling the necessary classes are in the same assembly. Now it's time to change our CustomerTest. [TestClass] public class CustomerTest: PersonTestBase { [TestMethod] public override void CustomerTestMethod() { //... } } We added a new Customer-specific method and removed method overrides from the base class, because its functionality suits us completely. What we got from this:
in fact, in the class of implemented 2 test methods: one came from the base class and one we implemented ourselves.
The Visual Studio Test List Editor says that we have only one theta honey - the method from the bash class does not appear and, accordingly, does not start.
It's a shame, but not fatal. We are come to the rescue by a regular utility MSTest, which solves everything, or almost everything, our problems. The advantages of this method are: