gpt4 book ai didi

c# - ApprovalTests 与 TestCase (Nunit) 使用相同的批准文件

转载 作者:行者123 更新时间:2023-12-02 20:30:08 24 4
gpt4 key购买 nike

我有一个问题,使用 ApprovalTests.Net 和 NUnit 运行的所有测试都使用相同的批准文件,其名称源自测试方法名称。

是否可以以某种方式为每个测试用例指定单独的批准文件?

[Test]
[TestCase("test",TestName="Test1")]
[TestCase("test2",TestName="Test2")]
Testing_Method(string param)
{
//somestuff
ObjectApprover.VerifyJson(someObject); // fails for second case
// because it uses the same
// approval file as the first case,
// which is not the same
}

最佳答案

您需要使用

ApprovalResults.ForScenario("extra info")

像这样:

[Test]
[TestCase("test",TestName="Test1")]
[TestCase("test2",TestName="Test2")]
Testing_Method(string param)
{
//somestuff
using (ApprovalTests.Namers.ApprovalResults.ForScenario(param))
{
ObjectApprover.VerifyJson(someObject);
}
}

这将产生 2 个批准文件:

TestClassName.Testing_Method.ForScenario.Test1.approved.json
TestClassName.Testing_Method.ForScenario.Test2.approved.json

关于c# - ApprovalTests 与 TestCase (Nunit) 使用相同的批准文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49035010/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com