This is a Xunit framework extension. It provides implementations that make it possible to run scenario using Xunit tests.
- It runs tests in order.
- It shares context between tests.
- It fails not run tests if one test fails in the test class.
- Use csharp roslyn code generator .net
- It automatically generates readable tests based on scenario text.
- Simplifies the creation of UI/API Automation Acceptance Tests.
- It is an additional extension for Xunit, so it is possible to create scenario tests and regular Xunit tests.
- Create a new Xunit test project
- Install the Xunit.Scenario nuget package
- Create the Setup class.
- Add assembly attribute with XunitScenarioTestFramework setup to it
using Xunit;
[assembly: TestFramework("Xunit.Scenario.Extension.XunitScenarioTestFramework", "Xunit.Scenario.Extension")]
- Create a new test class and add a scenario attribute with description, test cases will be generated as partial methods
- Implement partial methods.
using Xunit.Scenario.Extension;
using System.Threading.Tasks;
namespace ScenarioAutoGeneration
{
[Scenario(@"
* send first request
* send second request
* send third request
* send fourth request
")]
public partial class RequestFlowAutoGeneratedScenario : ScenarioSteps<RequestFlowAutoGeneratedScenario.State>
{
public RequestFlowAutoGeneratedScenario(State state) : base(state)
{
}
public partial Task S1_send_first_request()
{
return Task.CompletedTask;
}
public partial Task S2_send_second_request() { return Task.CompletedTask; }
public partial Task S3_send_third_request() { return Task.CompletedTask; }
public partial Task S4_send_fourth_request() { return Task.CompletedTask; }
public class State { }
}
}
- View samples