Shared Unit Tests with MSTest

北慕城南 提交于 2019-12-12 18:35:27

问题


I have approximately 5-6 reports, they are structured the same, using Watin, I'm testing each one of these reports.

I have a shared test, I call "ReportBaseTests"..

    public class ReportBaseTests
    {
        public string MenuName { get; set; }

        public ReportBaseTests(string name)
        { this.MenuName = name; }

        [TestMethod]
        public void Perform_Invalid_Date_Range()
        {
        }
    }

but in each of my tests, I have...

    [TestClass]
    public class Report1Tests : ReportBaseTests
    {
        public Report1Tests()
            : base("Report 1")
        { }
    }

This works... each report will have a seperate Perform_Invalid_date_range, and it'll goto a different page... I was hoping someone had a better way to do this, as it also produces a seperate "non-runnable" test for the shared test since I didn't include the [TestClass]

Now, I know I could use NUnit and pass in arguments, however, I'm sticking with MSTest for the time being


回答1:


If you wanted, you could add TestContext support to your tests and have the ReportBaseTests.Perform_Invalid_Date_Range() parse the TestContext.FullyQualifiedTestClassName. For a simple test I think that's over kill.

For your solution: just put the [TestClass] attribute on ReportBaseTests and then mark ReportBaseTests as abstract. The "non-runnable" tests will disappear.



来源:https://stackoverflow.com/questions/7717315/shared-unit-tests-with-mstest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!