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

标签 c# visual-studio testing bdd specflow

我正在运行一个测试,我正在使用我的预期输出“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/

相关文章:

c# - 无法解密使用 AesManaged 加密的文件

visual-studio - Visual Studio 项目中的图标是什么意思?

c# - Windows 服务上传到 AWS S3

c# - 如何将原始数据显示为图像 (Visual Studio c#)

testing - QuickCheck 陷阱 22

angularjs - 单击表中的列 - Protractor

c# - 如何检测游戏对象是否超出重叠范围

c# - 从 Unity 中的另一个脚本调用 IEnumerator 方法并获取其返回值

c# - 在 C# 中,如何将空检查添加到动态快速代码中

java - 是否可以模拟 System.identityHashCode?