某一天我的同事提醒我說新版的 Rider,SpecFlow for Rider 上不能使用了,於是我暫緩更新了一段時間,現在已經有 Reqnroll 方案。這裡有 Reqnroll 誕生原因,From SpecFlow to Reqnroll: Why and How • Reqnroll,總結內容就是 SpecFlow 已經很長一段時間沒有更新,所以作者決定 Fork SoecFlow 專案,名為 Reqnroll,現在我要來體驗 Reqnroll 跟過往的 SpecFlow 有沒有甚麼不一樣

開發環境
- Windows 11 Home
- Rider
設定步驟
<ItemGroup>
<Content Include="**/*.feature"/>
</ItemGroup>
套件安裝後,會有 Reqnroll 的專案範本套件

專案建立後,套件都升級到最新


這個專案範本需要調整一下才能運行
using FluentAssertions;
namespace App1.Steps;
[Binding]
public sealed class CalculatorStepDefinitions
{
// For additional details on Reqnroll step definitions see https://go.reqnroll.net/doc-stepdef
private readonly ScenarioContext _scenarioContext;
public CalculatorStepDefinitions(ScenarioContext scenarioContext)
{
this._scenarioContext = scenarioContext;
}
[Given("the first number is (.*)")]
public void GivenTheFirstNumberIs(int number)
{
this._scenarioContext.Set(number, "FirstNumber");
}
[Given("the second number is (.*)")]
public void GivenTheSecondNumberIs(int number)
{
this._scenarioContext.Set(number, "SecondNumber");
}
[When("the two numbers are added")]
public void WhenTheTwoNumbersAreAdded()
{
var firstNumber = this._scenarioContext.Get<int>("FirstNumber");
var secondNumber = this._scenarioContext.Get<int>("SecondNumber");
var cancellation = new Cancellation();
var actual = cancellation.Add(firstNumber, secondNumber);
this._scenarioContext.Set(actual, "Actual");
}
[Then("the result should be (.*)")]
public void ThenTheResultShouldBe(int result)
{
this._scenarioContext.Get<int>("Actual").Should().Be(result);
}
}
public class Cancellation
{
public int Add(int firstNumber, int secondNumber)
{
return firstNumber + secondNumber;
}
}
最後,執行測試的結果如下

Reqnroll vs SpecFlow
接下來就測試一下,跟 SpecFlow 有沒有差太多
- 測試步驟不存在按 Alt+Enter,產生測試步驟

- 新增一個空的 feature 檔案
看起來沒有這個功能 QQ

以上,使用上跟以往的 SpecFlow 沒有太大的差異,期待作者可以繼續維護它了,更多的內容請參考 Reqnroll Documentation
若有謬誤,煩請告知,新手發帖請多包涵
Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET