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

做~自己de王妃 提交于 2019-11-30 05:27:53

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