C#Nunit-传递带收益率的源数据时,并行运行两个测试



我希望每次将ReportFilePath设置为变量时,要返回的每组数据,对返回的每组数据进行一次和第二个测试。我只能进行一次测试,但我认为那太大了

private string reportFilePath;
[Test]
[TestCaseSource(typeof(TestData.SwiftReporting), "GenerateDailyLargeExposureReport")]
[Order(4)]
public async Task ShouldGenerateDailyLargeExposureReport(int year, int month, int day)
    {
        ReportResponseModel dailyLargeExposureReport = new ReportResponseModel();
        DateTime date = new DateTime(year, month, day).Date;
        string formattedDate = date.ToString("d");
        dailyLargeExposureReport = await ReportLogic.RequestReport(date, (int)ReportsEnum.DailyLargeExposureReport, null, AuthToken);
        dailyLargeExposureReport.Should().NotBeNull();
        reportFilePath = dailyLargeExposureReport.FilePath;
    }

[Test]
[TestCaseSource(typeof(TestData.SwiftReporting), "DownloadDailyLargeExposureReport")]
[Order(8)]
public async Task ShouldDownloadDailyLargeExposureReport(int accountCount)
    {
        DailyLargeExposureReportModel outputReport = new DailyLargeExposureReportModel();
        outputReport = (DailyLargeExposureReportModel)await ReportLogic.DownloadReport(reportFilePath, ReportsEnum.DailyLargeExposureReport, AuthToken);
        List<DailyLargeExposureAccountModel> reportAccounts = outputReport.Accounts;
        reportAccounts.Count().Should().Be(7);
    }

这是我的数据:

public static IEnumerable<TestCaseData> GenerateDailyLargeExposureReport
    {
        get
        {
            yield return new TestCaseData(2017, 1, 2)
                .SetName("Generate DLE report for Account1, Jan 2");
            yield return new TestCaseData(2017, 1, 3)
                .SetName("Generate DLE report for Account1, Jan 3");
        }
    }
public static IEnumerable<TestCaseData> DownloadDailyLargeExposureReport
    {
        get
        {
            yield return new TestCaseData(3)
                .SetName("Get data for Account1, Jan 2");
            yield return new TestCaseData(5)
                .SetName("Get data for Account1, Jan 3");
        }
    }

所以我想在每个IEnumerable中的第一组数据进行两个测试,然后再使用第二组进行。

对不起,除非您将[Parallelizable]添加到这两种方法中,否则不可能这样做。但这将允许所有四个测试并行进行,这不是您想要的。

重组的一种方法是使用TestFixtureSourceAttribute创建一个包含两个测试的参数化灯具。您可以使固定实例不可行,以使它们没有一起运行,但是单个测试可行,以便它们。

最新更新