Kjara
Kjara

Reputation: 2902

hide test method in child test class

I have two test classes where one inherits from the other, like this:

[TestClass]
public class TestClassBase
{
    // does some actual testing (load file, call methods, do Asserts and such)
    protected virtual DoTest(string fileName) { ... }

    [TestMethod]
    public void TestFileFoo() { DoTest("fooFile"); }

    [TestMethod]
    public void TestFileBar() { DoTest("barFile"); }

    ...
}

[TestClass]
public class TestClassChild : TestClassBase
{
    // is just a little bit different from base method
    protected override DoTest(string fileName) { ... }
}

I am doing it this way because the TestClassBase has around 100 tests that test a certain aspect, and now I added a new functionality that I want to test in the same 100 files in TestClassChild. Copy-pasting (i.e. using two classes not connected via inheritance) is no option from maintainability perspective. Some tests are marked with [Ignore] (they are not ready yet) which is fine with inheritance because the new functionality is a special case of the old one, i.e. if the old one does not work as expected, it does not make sense to test the new one.

But there is a little difference that doesn't work well with inheritance: There are some tests (in fact just one) that should be done in TestClassBase but not in TestClassChild. Is there a way to achieve that?

Own thoughts:

Upvotes: 1

Views: 191

Answers (0)

Related Questions