Is defining TestMethod's in test base classes not supported by MsTest?

前端 未结 3 1618
南旧
南旧 2021-02-11 22:31

This question concerns a general unit test technique with a potentially very useful wide range of applicable scenarios. But it is easier to understand with an example to illustr

3条回答
  •  臣服心动
    2021-02-11 22:41

    Using VS 2010 I am not seeing the same behavior as you are. When I copied your 2 classes into a test project and compiled it I got the output:

    UTA004: Illegal use of attribute...The TestMethodAttribute can be 
    defined only inside a class marked with the TestClass attribute
    

    So I marked EqualsFixutureBase:

    [TestClass]
    public abstract class EqualsFixtureBase
    {
    ...
    }
    

    Now it compiles without warning and when I select run tests for ExampleOfAnEqualsTestFixture it runs Foo and all 5 of the inherited equals tests. Also when I copy the ExampleOfAnEqualsTestFixture and use it for int and run the tests for the solution I see all 5 inherited tests running (and passing) for the example string class and the example int class.

    Are you doing something in addition to your example which might be causing your problem?

提交回复
热议问题