gpt4 book ai didi

c# - 自动化 'Then' 步骤 BDD C# Specflow 的问题

转载 作者:行者123 更新时间:2023-11-28 21:07:55 30 4
gpt4 key购买 nike

我正在运行一个测试,我正在使用我的预期输出“6677,6677_6677,3001,6”验证文件(例如 irm_xxx_lkdd_xuxt.csv.ovr)的输出

我遇到的问题是我的下面的代码没有被我的 specflow“Then”步骤识别。我认为问题可能是因为我正在使用 Nunit 测试用例。有办法解决这个问题吗?或者我可以在我的 ValidateMeasurement 方法中结合我的文件路径和预期结果

    [Then("Transfer measure should be generated for (.*)")]


[TestCase("irm_xxx_lkdd_xuxt.csv.ovr", "6677,6677_6677,3001,6")]
[TestCase("irm_xxx_lkdd_fcvt.csv.ovrr", "6677,6677_6677,3001,6")]
[TestCase("irm_xxx_lkdd_fbvt.csv.ovrr", "6677,6677_6677,3001,6")]

public void ValidateMeasurement(string path, string expected)
{
const string processFilePath = "/orabin/app/product/inputs/ff/actuals/";
var actual = Common.LinuxCommandExecutor
.RunLinuxcommand($"cat {processFilePath}{path}");

Assert.AreEqual(expected, actual);

}



Given I Loaded LifeCycle Measurement for Current
And Inventory interface is generated
When Inventory batch is executed
Then Transfer measure should be generated Current
Examples:
| Lifecyclestatus |
| PreNew |
| New |
| Current |
| Clearance |
| Old |

最佳答案

不要混合 BDD 和 NUnit 测试用例。 Specflow 在后台生成 NUnit 测试,但这并不意味着您必须考虑 BDD,因为它与单元测试有任何关系。

您的用例应该是 Examples,这样它将在后台转换为测试用例 - 但对您来说它应该是透明的,因为它可能是幕后的任何其他引擎。

所以 - 在不知道任何进一步细节的情况下 - 我会这样做:

Scenario Outline: My fantastic test with multiple cases
Given I have a <Path>
When I perform a test
Then the expected result is <Expected>

Examples:
| Path | Expected |
| irm_xxx_lkdd_xuxt.csv.ovr | 6677,6677_6677,3001,6 |
| irm_xxx_lkdd_fcvt.csv.ovrr | 6677,6677_6677,3001,6 |
| irm_xxx_lkdd_fbvt.csv.ovrr | 6677,6677_6677,3001,6 |

Given步骤中,您可以存储任何配置(也许只是存储路径是一个过于简单的示例),When步骤用于进行实际测试,并且最后,在 Then 步骤中执行断言。

[Binding]
public class MyFantasticFeatureBindings
{
[Given("I have a (.*)")]
public void ConfigureTest(string path)
{
// setup any configuration here - actually it can be the expected value, too
ScenarioContext.Current.Set(path, nameof(path));
}

[When("I perform a test")]
public void DoTest()
{
// obtain configuration, do the test and store the results and possible errors
var path = ScenarioContext.Current.Get<string>("path");

var result = PerformTest(path); // TODO - you have to implement this

ScenarioContext.Current.Set(result, nameof(result));
}

[Then("the expected result is (.*)")]
public void Assertions(string expectedResult)
{
var actualResult = ScenarioContext.Current.Get<string>("result");
Assert.AreEqual(expectedResult, actualResult);
}
}

关于c# - 自动化 'Then' 步骤 BDD C# Specflow 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50675507/

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