RecordVisitors- BDD–part 9
It is recommended to have tests. And better is to see the output of the tests in some readable format .
On other hand, I do not like full BDD frameworks as SpecFlow – I think that are too overkill in order to achieve less.
So – something like https://github.com/LightBDD/LightBDD seems to fit the bill.
After you read the documentation, it is not so difficult. You transform test from
[Fact] public async void TestFakeUser() { // Arrange var client = _factory.CreateClient(); // Act var response = await client.GetStringAsync("/recordVisitors/AllVisitors5Min"); // Assert var str = "JeanIrvine"; Assert.True(response.Contains(str), $"{response} must contain {str}"); }
into
HttpClient client; string response; private void Given_The_Application_Starts() { StepExecution.Current.Comment("!!!Start application!!!!"); client = _factory.CreateClient(); } private async Task When_The_User_Access_The_Url(string url) { response = await client.GetStringAsync(url); } private void Then_The_Response_Should_Contain(string str) { Assert.True(response.Contains(str), $"{response} must contain {str}"); } [Scenario] [ScenarioCategory("VisitorRecord")] public async void TestFakeUser() { await Runner .AddSteps(Given_The_Application_Starts) .AddAsyncSteps( _ => When_The_User_Access_The_Url("/recordVisitors/AllVisitors5Min") ) .AddSteps( _ => Then_The_Response_Should_Contain("JeanIrvine") ) .RunAsync(); }
Yes, it seems some more code – but you can re-use the functions and , more, the documentation looks great!
The results can bee seen at https://record-visitors.readthedocs.io/en/latest/BDD/LightBDDReport/
Leave a Reply