Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

InitializeAsync is not called for Scenario tests #655

Open
DanHampl opened this issue Mar 11, 2020 · 9 comments
Open

InitializeAsync is not called for Scenario tests #655

DanHampl opened this issue Mar 11, 2020 · 9 comments

Comments

@DanHampl
Copy link

DanHampl commented Mar 11, 2020

Version(s)

"2.4.1"

To reproduce

using System.Threading.Tasks;
using FluentAssertions;
using Xbehave;
using Xunit;

namespace Tests.Scenarios.Student
{
    [Collection("Example")]
    public class ExampleTest : IAsyncLifetime
    {
        private bool InitializationCompleted;

        public ExampleTest()
        {
        }

        public Task InitializeAsync()
        {
            InitializationCompleted = true;
            return Task.CompletedTask;
        }

        public Task DisposeAsync()
        {
            InitializationCompleted = false;
            return Task.CompletedTask;
        }

        // Works flawlessly
        [Fact]
        public Task TestFact()
        {
            Assert.True(InitializationCompleted);
            return Task.CompletedTask;
        }

        // InitializeAsync is not called
        [Scenario]
        public Task TestScenario()
        {
            "This should be working but initialization is not called for scenario tests."
                .x(() => InitializationCompleted.Should().Be(true));
            return Task.CompletedTask;
        }
    }
}

Expected behavior

IAsyncLifetime will be called for [Scenario]

Actual behaviour

InitializeAsync is not called for [Scenario]

Workarounds

Call InitializeAsync from the test itself

Additional context

Works flawlessly for [Fact]

@DanHampl DanHampl added the bug label Mar 11, 2020
@adamralph
Copy link
Owner

@DanHampl thanks for raising this. I'll look into it.

@WTobor
Copy link

WTobor commented Nov 6, 2020

Hello - do you have an update here?

@adamralph
Copy link
Owner

@WTobor I'm afraid not. It's on my radar, but I've had no time to look into it yet.

@redoz
Copy link
Contributor

redoz commented Nov 20, 2020

I think I just ran into this myself and it's kind of blocking me, would you take a PR for this if I can figure out what the problem is?

@adamralph
Copy link
Owner

@redoz sure, please feel free to send a PR.

@redoz
Copy link
Contributor

redoz commented Nov 20, 2020

@adamralph I have to see if I can fix it first 😄

@redoz
Copy link
Contributor

redoz commented Nov 20, 2020

@adamralph So apparently I need learn how to read better, because I thought this was about IAsyncLifetime on the collection itself and that appears to work fine. So I'm going to investigate why it doesn't work in my actual project, I guess I made a mistake somewhere.

Meanwhile, do you want a PR for the tests I added that makes sure that IAsyncLifetime is called correctly on collection fixtures that are not injected into the test class?

@adamralph
Copy link
Owner

Meanwhile, do you want a PR for the tests I added that makes sure that IAsyncLifetime is called correctly on collection fixtures that are not injected into the test class?

Sure, I'll happily take a look.

@adamralph
Copy link
Owner

FYI I've started the ball rolling by pushing a failing test for this to https://github.com/adamralph/xbehave.net/tree/async-class-fixture

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants