自动化问题'然后'步骤BDD C#Specflow

时间:2018-06-04 07:36:39

标签: c# visual-studio testing bdd specflow

我正在运行测试,我正在使用我预期的输出来验证文件的输出(例如irm_xxx_lkdd_xuxt.csv.ovr)#66; 6677,6677_6677,3001,6&#34; < / p>

我遇到的问题是我的代码未被我的规范识别出来&#39;然后&#39;步。我认为这个问题可能是因为我正在使用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             |

1 个答案:

答案 0 :(得分:2)

不要混用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步骤1}}步骤你做断言。

[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);
    }
}