C# MS测试单个测试的DataTestMethod超时

C# MS测试单个测试的DataTestMethod超时,c#,automated-tests,timeout,mstest,data-driven-tests,C#,Automated Tests,Timeout,Mstest,Data Driven Tests,我使用MSTest(2.1.2),我有一个数据驱动的测试 [DataTestMethod] [ExpenseTypesData] [Timeout(600000)] public void ManualExpenseReportTest(string category) { } 是否可以为单个数据行测试而不是所有数据行设置超时 无论我有2行还是200行,这个测试都会在超时时失败。不用说,我不知道要执行多少测试,所以更改一个数字不是一个选项。除此之外,我不想让一个卡住的测试保存其他数据行。在gi

我使用MSTest(2.1.2),我有一个数据驱动的测试

[DataTestMethod]
[ExpenseTypesData]
[Timeout(600000)]
public void ManualExpenseReportTest(string category)
{
}
是否可以为单个数据行测试而不是所有数据行设置超时


无论我有2行还是200行,这个测试都会在超时时失败。不用说,我不知道要执行多少测试,所以更改一个数字不是一个选项。除此之外,我不想让一个卡住的测试保存其他数据行。

在github上正在讨论这个问题:因为用户期望
TimeoutAttribute
将根据
DataRow
应用。不幸的是,最后一个答案是从2020年8月开始的,所以解决这个问题的希望不大

如果您确实需要它,并且希望构建自己的解决方案,您可以将测试包装在异步
任务中,并等待每行所需的任何超时。大概是这样的:

[TestClass]
public class TestClass1
{
    private int Timeout => 500;

    [DataTestMethod]
    [DataRow(100)]
    [DataRow(1000)]
    [DataRow(250)]
    [DataRow(1500)]
    [DataRow(100)]
    public void Test1(int delay)
    {
        Task task = Task.Run(() =>
        {
            Thread.Sleep(delay); // Your test goes here

            Assert.IsTrue(true); // Your asserts go here
        });

        if (!task.Wait(Timeout))
            Assert.Fail("Test failed with timeout");
    }
}

谢谢正如我从中发现的,使用PostSharp decorators的方法将允许创建自己的超时decorator。遗憾的是,微软忽略了数据驱动的测试超时。