All Projects → ttutisani → Xunit.gherkin.quick

ttutisani / Xunit.gherkin.quick

Licence: mit
BDD in .NET Core - using Xunit and Gherkin (compatible with both .NET Core and .NET)

Projects that are alternatives of or similar to Xunit.gherkin.quick

scenari
Clojure BDD library - Executable Specification with Behavior-Driven Development
Stars: ✭ 57 (-53.66%)
Mutual labels:  bdd, gherkin
gavel-spec
Behavior specification for Gavel, validator of HTTP transactions
Stars: ✭ 105 (-14.63%)
Mutual labels:  bdd, gherkin
Awesome-Cucumber
A collection of awesome Cucumber and Gherkin-related resources
Stars: ✭ 33 (-73.17%)
Mutual labels:  bdd, gherkin
featurebook
A command line tool (and Node.js library) for generating beautiful system specifications from Gherkin source files.
Stars: ✭ 40 (-67.48%)
Mutual labels:  bdd, gherkin
Behat
BDD in PHP
Stars: ✭ 3,696 (+2904.88%)
Mutual labels:  bdd, gherkin
cucumber-performance
A performance testing framework for cucumber
Stars: ✭ 28 (-77.24%)
Mutual labels:  bdd, gherkin
karate-runner
VSCode Extension for Karate
Stars: ✭ 23 (-81.3%)
Mutual labels:  bdd, gherkin
django-aloe-bdd
BDD with Django and Aloe
Stars: ✭ 27 (-78.05%)
Mutual labels:  bdd, gherkin
behave-restful
BDD Framework to Test REST Services and APIs
Stars: ✭ 47 (-61.79%)
Mutual labels:  bdd, gherkin
bat
Gherkin based DSL for testing HTTP APIs via Cucumber.JS
Stars: ✭ 30 (-75.61%)
Mutual labels:  bdd, gherkin
mocha-cakes-2
A BDD plugin for Mocha testing framework
Stars: ✭ 44 (-64.23%)
Mutual labels:  bdd, gherkin
Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+4369.11%)
Mutual labels:  bdd, gherkin
cucumber6-ts-starter
Starter project to write and debug cucumber-js features in TypeScript language
Stars: ✭ 62 (-49.59%)
Mutual labels:  bdd, gherkin
cucumber-jvm-examples
Cucumber-jvm 5.0.0 examples with Maven
Stars: ✭ 20 (-83.74%)
Mutual labels:  bdd, gherkin
aloe
Behavior Driven Development using Cucumber for Python
Stars: ✭ 63 (-48.78%)
Mutual labels:  bdd, gherkin
kheera-testrunner-android
BDD Framework for Android
Stars: ✭ 18 (-85.37%)
Mutual labels:  bdd, gherkin
Nightwatch Cucumber
[DEPRECATED] Cucumber.js plugin for Nightwatch.js.
Stars: ✭ 243 (+97.56%)
Mutual labels:  bdd, gherkin
docs
Cucumber user documentation
Stars: ✭ 110 (-10.57%)
Mutual labels:  bdd, gherkin
gherkin
Pure Rust implementation of Gherkin language (`.feature` file) for Cucumber testing framework.
Stars: ✭ 41 (-66.67%)
Mutual labels:  bdd, gherkin
Symfonyextension
🎼 Extension integrating Behat with Symfony.
Stars: ✭ 376 (+205.69%)
Mutual labels:  bdd, gherkin

Nuget: Xunit.Gherkin.Quick on Nuget Xunit.Gherkin.Quick Downloads on Nuget

Build Status: Build status


Xunit.Gherkin.Quick

Xunit.Gherkin.Quick is a lightweight, cross platform BDD test framework (targets .NET Standard, can be used from both .NET and .NET Core test projects). It parses Gherkin language and executes Xunit tests corresponding to scenarios.

Project Sponsors

Showcase your company's logo here by sponsoring this project!

NOTE: If you want to become a sponsor, you can find a sponsoring link on this page, and contact us to provide your logo and details.

Thank you for consideration, and enjoy the framework!

Getting Started

Prefer video format? Watch how to get started with BDD and Xunit.Gherkin.Quick on Youtube.

We'll quickly setup our project, write our first BDD test, and then run it.

Xunit test project

Create a new or open existing Xunit test project. Xunit.Gherkin.Quick needs to be used with Xunit.

Install nuget package

Package name to search for through GUI: Xunit.Gherkin.Quick

Package Manager:

Install-Package Xunit.Gherkin.Quick

.NET Core:

dotnet add package Xunit.Gherkin.Quick

These steps should take care of the installation, but if you need more info about setup or the nuget package, click here: https://www.nuget.org/packages/Xunit.Gherkin.Quick/

Create Gherkin feature file

Create a new text file. Name it as AddTwoNumbers.feature.

Important: change feature file properties to ensure it gets copied into output directory. Set the value of Copy to Output Directory to Copy Always or Copy if Newer. See Copying Feature Files for more options.

NOTE: In practice, you can name your files in any way you want, and .feature extension is not necessary either.

Copy the below code and paste it into your feature file:

Feature: AddTwoNumbers
	In order to learn Math
	As a regular human
	I want to add two numbers using Calculator

Scenario: Add two numbers
	Given I chose 12 as first number
	And I chose 15 as second number
	When I press add
	Then the result should be 27 on the screen

This is a BDD style feature written in Gherkin language.

Now it's time to implement the code to run scenarios of this feature.

Note: at this point, the new feature file's scenarios will not be discovered by the test runner either via Visual Studio or via the command line execution. By default, you need to have a corresponding feature class in your project which refers to this new feature file. If you want to instead see every new feature file's scenarios right after they are added without the necessity to have the corresponding feature class, please see Handling Not-Implemented Feature Files.

Implement Feature Scenario

Implementing a scenario simply means writing methods in the Feature-derived class. Goal is to ensure that each scenario step above will match a method by using regex syntax. If we miss a step and it does not match a method, we will receive an error when we try to run the scenario test.

Here is how we can implement the scenario of the above feature:

[FeatureFile("./Addition/AddTwoNumbers.feature")]
public sealed class AddTwoNumbers : Feature
{
    private readonly Calculator _calculator = new Calculator();

    [Given(@"I chose (\d+) as first number")]
    public void I_chose_first_number(int firstNumber)
    {
        _calculator.SetFirstNumber(firstNumber);
    }

    [And(@"I chose (\d+) as second number")]
    public void I_chose_second_number(int secondNumber)
    {
        _calculator.SetSecondNumber(secondNumber);
    }

    [When(@"I press add")]
    public void I_press_add()
    {
        _calculator.AddNumbers();
    }

    [Then(@"the result should be (\d+) on the screen")]
    public void The_result_should_be_z_on_the_screen(int expectedResult)
    {
        var actualResult = _calculator.Result;

        Assert.Equal(expectedResult, actualResult);
    }
}

Notice a couple of things:

  • FeatureFile attribute for the class refers to the feature file location (relative to the project root, not relative to the class file). You don't need to apply this attribute if you keep your feature files in the root directory of your project, because that's where it will be located by default. Buf if you keep it under a sub-folder (which I do), then make sure to specify the file location (either relative or absolute) using this attribute.

  • Given, When and Then attributes specify scenario step text which they need to match. If you want to extract value from the text, you need to use parentheses. Behind the scenes this is done using .NET Regex syntax. Regex group values are passed as argument values. You can also use And and But attributes, which work similarly.

  • Scenario step method can be async, or can be a regular method, just as shown in the example above.

Run Scenario

Build BDD tests project.

If you use command line to run unit tests, simply run them as always (e.g., run dotnet test command inside a solution or test project folder). You should see the scenario full name in the results as a newly added unit test name.

If you use Visual Studio to run unit tests, open Test Explorer to see the new test item (important: use built-in Test Explorer, not ReSharper or anything else). Right click and run it as you would usually run unit tests through test explorer.

Unit test name in this case will be "AddTwoNumbers :: Add two numbers", which is a combination of feature name "AddTwoNumbers" and scenario name "Add two numbers".

Screenshot of scenario test run

Add More Scenarios

If the feature has multiple scenarios, add them to the same feature file. They will show up as additional tests in the test explorer. And they will need additional methods in the same feature class for execution.

Got Stuck?

Look into our issues if your problem was already resolved. Also try searching StackOverflow.

Feel free to post your question/problem either into our issues repository, or into StackOverflow.

Check out a fully-working sample project with BDD test implementations for every supported feature: ProjectConsumer.

Special Thanks

I want to send special Thank You to all the contributors, which you can see here: https://github.com/ttutisani/Xunit.Gherkin.Quick/graphs/contributors

Specifically:

Documentation and Reference

See Also

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].