SpecFlow used in visual studio

https://docs.specflow.org/projects/getting-started/en/latest/GettingStarted/Step1.html

https://docs.specflow.org/projects/getting-started/en/latest/GettingStarted/Step2.html

https://docs.specflow.org/projects/getting-started/en/latest/GettingStarted/Step3.html

 

Create SpecFlow project - Continue  step4 

SpecFlow + Runner activation  step5

Bind the first step  step6

 

The purpose of this feature file is to document the expected behavior of the calculator in a way that it is both human-readable and suitable for test automation.

SpecFlow uses the Gherkin language where you can phrase the scenarios using Given/When/Then steps.

Currently there is a single scenario (automatically added by the SpecFlow project template) that describes how adding two numbers should work with the calculator.

 

Here is a closer look at the Gherkin scenario used in this template:

Scenario: Add two numbers
    Given the first number is 50
    And the second number is 70
    When the two numbers are added
    Then the result should be 120

Based on the scenario text, SpecFlow generates an automated test that executes the scenario. However, it is not yet defined what the steps of the scenario should actually “do”.

 

2- Right-click the first Given step “Given the first number is 50” and select either the “Go To Definition” or the “Go To Step Definition” command.

Visual Studio locates the step definition (binding) that belongs to this step. In this example, it opens the CalculatorStepDefinitions class and jumps to the GivenTheFirstNumberIs method.

 

*The step definition is located based on the [Binding] attribute on the class and the [Given] attribute on the method. The regular expression of the Given attribute matches the text of the scenario step.

 

3- Add the below field to the class to instantiate the calculator that we want to test and created in Step 2 of this guide (SUT).

        private readonly Calculator _calculator = new Calculator();

 

Add Living Documentation  step9

2- Install the LivingDoc CLI as a global dotnet tool.

dotnet tool install --global SpecFlow.Plus.LivingDoc.CLI

 

3- Navigate to the output directory of the SpecFlow project. In this example the solution was setup in the C:\work folder.

cd C:\work\SpecFlowCalculator\SpecFlowCalculator.Specs\bin\Debug\netcoreapp3.1

4- Run the LivingDoc CLI by using the below command to generate the HTML report.

livingdoc test-assembly SpecFlowCalculator.Specs.dll -t TestExecution.json

5- Open the generated HTML with your favorite browser. The HTML file is stored in the same folder as the output directory of the SpecFlow project.

C:\work\SpecFlowCalculator\SpecFlowCalculator.Specs\bin\Debug\netcoreapp3.1\LivingDoc.html

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(85)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-05-25 xml security issue
2020-05-25 Non-scalar subquery in place of a scalar
2019-05-25 域名信息备案查询 以及 国家企业信用信息公示
2019-05-25 404. Sum of Left Leaves
2019-05-25 git修改commiter date
2017-05-25 Exception: Operation xx of contract xx specifies multiple request body parameters to be serialized without any wrapper elements.
2017-05-25 如何测试WCF Rest
点击右上角即可分享
微信分享提示