0

Not duplicate of: Inherited test class from generic base is ignored in MSTest

In my case, the test classes are in the same namespace/assembly.

When unittesting classes which have a lot in common, I would like to use a base test class with a generic parameter. I have boiled the problem down to the following, where my base test method is not being executed, but ONLY in the generic case.

Non-generic: Base test method is EXECUTED:

[TestClass]
public class DerivedTestClass : BaseUnitTest
{
    protected override string ReturnMeSomething(object obj)
    {
        return "test1" + obj.ToString();
    }

    [TestMethod]
    public void derived_test()
    {
    // This is executed
    }
}

[TestClass]
public abstract class BaseUnitTest
{
    [TestMethod]
    public void base_test()
    {
        // This is executed
    }
    protected abstract string ReturnMeSomething(object obj);
}

Generic: Base test method in generic base class is NOT EXECUTED:

[TestClass]
public class DerivedTestClass : BaseUnitTest<string>
{
    protected override string ReturnMeSomething(string s)
    {
        return "test1" + s;
    }

    [TestMethod]
    public void derived_test()
    {
        // This is executed
    }
}

[TestClass]
public abstract class BaseUnitTest<T>
{
    [TestMethod]
    public void base_test()
    {
        // This is NOT executed
    }
    protected abstract string ReturnMeSomething(T t);
}

Can anyone tell me the reason for this?

Community
  • 1
  • 1
Stephan Møller
  • 1,247
  • 19
  • 39

1 Answers1

0

After a few days, this suddenly works (!!). If anyone ever experiences this same, odd behavior, please write a comment here. I would suggest anyone to reboot and clean+rebuild everything and try again.

Stephan Møller
  • 1,247
  • 19
  • 39