Data driven tests generated in ClassInitialize: no longer working in Visual Studio 2012

后端 未结 1 2003
你的背包
你的背包 2020-12-29 17:25

I have upgraded from Visual Studio 2010 to Visual Studio 2012.

In my unit test project, I have a [ClassInitialize] method which generates a CSV file which I then fee

相关标签:
1条回答
  • 2020-12-29 17:59

    MSTestHacks might help.

    It allows an IEnumberable on your test class to be used as the DataSource for your TestMethod.

    From the website:

    Runtime DataSource

    You MUST inherit your test class from TestBase

    [TestClass]
    public class UnitTest1 : TestBase
    { }
    

    Create a Property, Field or Method, that returns an IEnumerable

    [TestClass]
    public class UnitTest1 : TestBase
    {
        private IEnumerable<int> Stuff
        {
            get
            {
                //This could do anything, fetch a dynamic list from anywhere....
                return new List<int> { 1, 2, 3 };
            }
        }
    }
    

    Add the DataSource attribute to your test method, pointing back to the IEnumerable name created earlier. This needs to be fully qualified.

    [TestMethod]
    [DataSource("Namespace.UnitTest1.Stuff")]
    public void TestMethod1()
    {
        var number = this.TestContext.GetRuntimeDataSourceObject<int>();
    
        Assert.IsNotNull(number);
    }
    
    0 讨论(0)
提交回复
热议问题