Giter VIP home page Giter VIP logo

givenwhenthentemplatetocsharp's Introduction

Given-When-Then template to C# is a commandline tool to convert given-when-then clauses to xUnit.net tests. The structure of unit tests is inspired by this and this article.

Build status

Quick start

Assuming that a feature is described in /path/to/features/GuessTheWord.feature with this content

Given the Maker has started a game with the word silky
    When the Breaker joins the Maker's game
        Then the Breaker must guess a word with 5 characters

Run this in the repository's root directory

cd src/GivenWhenThenTemplateToCSharp
dotnet run -- --features /path/to/features/GuessTheWord.feature --namespace ProductionCode.Tests

Or in the commandline where gwt.exe is located

gwt --features /path/to/features/GuessTheWord.feature --namespace ProductionCode.Tests

Test file is generated in the same directory as the feature file, i.e. /path/to/features/GuessTheWordTest.cs

namespace ProductionCode.Tests
{
    public class GuessTheWordTest
    {
        public class Given_the_Maker_has_started_a_game_with_the_word_silky : GuessTheWordTest
        {
            public class When_the_Breaker_joins_the_Makers_game : Given_the_Maker_has_started_a_game_with_the_word_silky
            {
                [Fact]
                public void Then_the_Breaker_must_guess_a_word_with_5_characters()
                {
                    // arrange
                    
                    
                    // act
                    
                    // assert
                }
            }
        }
    }
}

Being noted that both test class and generated file have a Test-suffix.

Multiple given-when-then in a feature are also supported. Optionally use blank lines to make the specs easier to read.

Given I am logged in as Dr. Bill
    When I try to post to "Expensive Therapy"
        Then I should see "Your article was published."
    When I try to post to "Greg's anti-tax rants"
        Then I should see "Hey! That's not your blog!"

Given I am logged in as Greg
    When I try to post to "Expensive Therapy"
        Then I should see "Your article was published."

Commandline options

  -f, --features     Required. Feature files to be converted

  -n, --namespace    (Default: TestsNamespace) Set the namespace of the generated tests

  --help             Display this help screen.

  --version          Display version information.

Notes

To build this console app as Windows 10 executable (.exe), run this command

dotnet build -c Release -r win10-x64

Credits and references

givenwhenthentemplatetocsharp's People

Contributors

sonbua avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.