ttutisani/Xunit.Gherkin.Quick

Tests stuck in Starting test execution, please wait when using async synchronously

iberodev opened this issue · 8 comments

I have been struggling a bit with a strange issue since I added a constructor to my Features in order to have a before and after scenarios as per https://github.com/ttutisani/Xunit.Gherkin.Quick/blob/master/docs/before-after-scenario-hooks.md

I included a constructor that contains an asynchronous call that should be awaited.

[FeatureFile("./Features/MyFeature.feature")]
public class MyFeature
    : Feature
{
    public MyFeature()
    {
        var container = MyDIHelper.RegisterAllDependencies();
        var eventStoreManager = container.Resolve<IEventStoreManager>();
        eventStoreManager.StartAsync().GetAwaiter().GetResult();
    }

    [Given(@"whatever")]
    public async Task GivenWhateverAsync()
    {
        // whatever given
    }

    [When(@"something happens")]
    public async Task WhenSomethingHappensAsync()
    {
           // whatever operation
    }

    [Then(@"assertion")]
    public void ThenWhatever()
    {
          // whatever assertion
    }
}

I have several features working in a similar way. I think this is important to notice.

When I run the whole test project either with resharper (All tests from solution) or with
dotnet test MyApp.ComponentTests/MyApp.ComponentTests.csproj -c Release
or with
dotnet vstest *ComponentTests/bin/Release/**/*ComponentTests.dll

I ran the dotnet commands in Windows and Linux, it didn't make any difference.

The test execution gets stuck at the Starting test execution, please wait.. step. However if I run the Features one by one it executes properly and it succeeds. So I suspected it had something to do with a bunch execution (in parallel or not).

I tried adding a xunit.runner.json with

{
  "parallelizeTestCollections": false,
  "maxParallelThreads": -1
}

but the result was the same, test execution stuck, no errors, just stuck forever.

Then I decided to make the asynchronous call without awaiting inside my constructors, like this:
eventStoreManager.StartAsync()

and it worked properly although sometimes the tests fail as you can imagine because sometimes the event store has not yet started the connection by the time the connection is used. So it's not ideal.

I suspect there is some issue with this framework.

@iberodev did my suggestion help? was it Xunit or something else?

I am still having issues that may be related to that. But probably it's due to my lack of understanding of this Gerkhin xUnit project.

I am failing to create even the simplest feature to test this. I always get a Test-cases are missing error.

I have a sample sandbox project where I am trying to set this up. Could you please let me know why this feature is incorrect?

Feature: SimpleScenario
	As a user
	I want to assign a variable name
	so that I can prove that the BDD approach works

Scenario: Simple Scenario
	Given I choose "foo" as the name
	When I assign the variable
	Then the name should be the assigned value

and the code

using FluentAssertions;
using Xunit.Gherkin.Quick;

namespace DiDrDe.DotNetTesteable.ComponentTests.Features
{
    [FeatureFile("./Features/SimpleScenario.feature")]
    public sealed class SimpleScenario
        : ComponentTestFeature
    {
        private string _name;

        public SimpleScenario()
        {
        }

        [Given(@"I choose ""(.*)"" as the name")]
        public void I_Choose_The_Name(string name)
        {
            _name = name;
        }

        [When(@"I assign the variable")]
        public void I_Assign_The_Variable()
        {
            _name = "bar";
        }

        [Then(@"the name should be the assigned value")]
        public void The_Name_Should_Be_The_Assigned_Value()
        {
            _name.Should().Be("bar");
        }
    }
}

Regex usually is the issue if it cannot match. By glancing at it quickly, regex seems to be fine, but please verify it yourself too.
I see that you are deriving from ComponentTestFeature. What is in that class? Try to derive from Feature and see if it starts working.
Also, please provide the exact error that you are getting.

Also check the path to the feature file:

Open the project location and go to bin folder and see the path to the feature file relative to the bin folder.
Path that you mentioned in the FeatureFile attribute should be relative to the bin folder.

If you don't see the feature file in the bin folder, check if you marked it as "copy always". By default, it does not copy text files to the output.

This all is mentioned in the quick start guide on the home page of the GitHub project. Make sure to follow it step by step and the issue should be resolved.

Let me know how it goes.

Thanks a lot and sorry, I had made a mistake by not selecting Copy Always on the feature file as clearly stated on the documentation (oops)

I am now able to prepare a scenario to check the original problem and see if it's xUnit related. Will update when ready.

@iberodev any updates on this issue, please?

I haven't heard back from you with any updates, so I will be closing this issue for now.
If you encounter problems, please come back to this or a new issue.