Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Before/After attributes for unit-test. #39

Closed
wants to merge 2 commits into from

Conversation

laneser
Copy link

@laneser laneser commented Jun 28, 2018

Sorry for empty description.

Those are hooks attributes for unit-test.

please reference for specflow http://specflow.org/documentation/Hooks/

@ttutisani
Copy link
Owner

Hi. Why do you think this feature is necessary? What's the use case?
Nobody has asked about this yet. So I assume you need it.
Can you please describe for what you need it specifically?

@laneser
Copy link
Author

laneser commented Jun 28, 2018

The project is a very good quick replace solution for specflow when we moved to dotnet core.
But the hook attributes in specflow does not support in the project.
So I think this is a good feature for the project.

@ttutisani
Copy link
Owner

This framework does not intend to replace specflow. That alone will not be enough to have this feature considered. I hope this does not come as a big frustration.
Can you please provide an example of a feature and scenario which require before/after methods?
If you can explain the need for it from feature/scenario standpoint, that can help in this process a lot.
Thank you!

@laneser
Copy link
Author

laneser commented Jun 28, 2018

For those unit-test which need initialization or destruction functions,
such as database creation and cleanup, we put those code in [BeforeScenario] and [AfterScenario].

I will not feel frustrated if you reject the feature, then I will use my forked project.
Thanks for your patient!

@ttutisani
Copy link
Owner

Thanks for clarifying!

Initialization code should go into constructor of the tester class (one that derives from Feature). Or, if you have an advanced case, you can use Collection Fixture from Xunit, which supports both setup and tear down methods. You can read about this here for example: https://stackoverflow.com/questions/12976319/xunit-net-global-setup-teardown

At this point, I would have to restrain from merging this feature. If I see a need for such functionality in the future, clearly from feature/scenario (Gherkin) test standpoint, then I will come back to this.
Sorry!

But if you think I'm misunderstanding something, please do let me know.
As I said, for what you described, Xunit has better ways (Collection Fixture), so I don't think I need to support something in addition.

@ttutisani
Copy link
Owner

Output is null because I assign to Output after constructor executes.

But, if you want Output to be not null, simply add ITestOutputHelper as your constructor parameter.
When constructor runs, use the parameter value, not Output property.

e.g.:

public sealed class MyFeature : Feature
{
    public MyFeature(ITestOutputHelper output2)
    {
        // output2 is not null, Output is null.
        var type = output2.GetType();
    }
}

@ttutisani
Copy link
Owner

Closing as out of scope. Thanks anyway for the effort!

@ttutisani ttutisani closed this Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants