Git Product home page Git Product logo

Comments (10)

richard-haslam avatar richard-haslam commented on June 10, 2024 1

I think Specflow uses the Given keyword as well so would make sense to work in a familiar way for people.

I have done exactly what you have suggested with a NuGet feed and working well. No hurry to implement, and thanks for providing this resource in the first place!

Thanks.

from xunit.gherkin.quick.

ttutisani avatar ttutisani commented on June 10, 2024

I need to check if the Gherkin parser (used by Xunit.Gherkin.Quick) is able to successfully consume a scenario with * keyword. If that is true, then matching that with any other keyword must not be a problem.

Worth trying. Thanks for pointing out!

from xunit.gherkin.quick.

ttutisani avatar ttutisani commented on June 10, 2024

Also, did you notice the support of multiple step definition matches per method? Does that solve your use case?

Basically, you can have the same method execute for two or more steps if it has multiple keyword attributes attached to it. For example, every method in this class matches two steps each:

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

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

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

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

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

        Assert.Equal(expectedResult, actualResult);
    }
}

from xunit.gherkin.quick.

richard-haslam avatar richard-haslam commented on June 10, 2024

I have feature files for long end to end tests written in star notation that I need to implement, I can change them all to 'Given' but it makes them harder to read.

I took a quick look at the Gherkin parser and it looks like the languages.json file soes support *
https://github.com/cucumber/cucumber/blob/master/gherkin/dotnet/Gherkin/gherkin-languages.json

I've had a quick go at adding a class for * to a download of your code but I can't get it working. I must be missing something.

Thanks

from xunit.gherkin.quick.

ttutisani avatar ttutisani commented on June 10, 2024

I see. End to end tests can be really long.

While I do agree that Xunit.Gherkin.Quick should support the full gherkin syntax (i.e., star notation too), I still believe that using * must be the last resort. Given/When/Then/etc keywords add clarity as to what you are referring to. Given and optional Ands denote context (precondition), When and optional Ands denote action (important interactions with the system or scenario), Then and optional Ands denote post-conditions and assertions (to verify the scenario is going well).

When you are dealing with long end-to-end tests, I can envision using Given-When-Then several times in the same scenario. i.e., Given comes again after Then because the end-to-end test can consist of multiple sub-scenarios and that is fine and normally supported by Gherkin language.

So, in your concrete case, to improve the long-run maintainability of your test feature files, I would suggest that you should try to use one of the concrete keywords instead of using *. That is from a conceptual standpoint.

As I said, Xunit.Ghekin.Quick was designed to support the full Gherkin language syntax, so it makes sense that it can parse * too, but that's a technical implementation and has nothing to do with the best practices of using Gherkin and BDD as such.

from xunit.gherkin.quick.

richard-haslam avatar richard-haslam commented on June 10, 2024

Thanks, I completely agree with everything you have said above. I'm in a position of attempting to get colleagues from Specflow to dotnet core, in the theory we will be more platform agnostic (and solve some other problems in the process), so not totally in control of the feature files.

from xunit.gherkin.quick.

richard-haslam avatar richard-haslam commented on June 10, 2024

With a little more playing around I have managed to get the start notation working, and out it here: https://github.com/Richie5555/Xunit.Gherkin.Quick

There is a simple test extended to show it working but probably needs more, and I have added a doc for it.

Please do use this code if it saves you time adding this feature, else I will not be offended if you don't.

from xunit.gherkin.quick.

ttutisani avatar ttutisani commented on June 10, 2024

Thanks @Richie5555 , I will incorporate pieces of your work into the code change when I get to it. One thing I want to point out though - from what I can tell, the * means that it matches any of the existing keywords in the code. So when I implement it, probably there will be no [Star()] attribute. Instead, you use * in the feature file and it will match [Given] or any other existing attribute. At least that how I interpreted the links that you provided initially in this issue. Although I need to research more before implementing. I want to ensure that the implementation follows how it's supposed to be working. This is just a guess based on first sight. It will complicate the implementation, but that's a trade-off.

Please know that I am a little stuck with other high priority work right now (writing a book and trying to finish 3-rd part of it). I hope that I will add the support for the star notation within a month period. It may be a little too long, but I can't do anything about it (one thing at a time).
If you can't wait so long, consider generating a local nuget file out of your changes and use that for now. There is a pack.cmd file under /source/Xunit.Gherkin.Quick which creates the nuget file. Sorry if this causes any inconvenience!

When I add the star notation support, I will post back to this discussion. Thanks for your patience!

from xunit.gherkin.quick.

ttutisani avatar ttutisani commented on June 10, 2024

This work is in progress on a star-notation-support branch. The work in progress can be previewed at https://github.com/ttutisani/Xunit.Gherkin.Quick/compare/star-notation-support?expand=1

from xunit.gherkin.quick.

ttutisani avatar ttutisani commented on June 10, 2024

New NuGet 3.5.0 is uploaded with the support of the star notation. It will be available for download after both the validation and indexing are complete (up to an hour). I am closing this ticket.

from xunit.gherkin.quick.

Related Issues (20)

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.