TNG / JGiven

Behavior-Driven Development in plain Java
http://jgiven.org
Apache License 2.0
437 stars 98 forks source link

Create proxy to allow JGiven to run with Class lifecycles #883

Open l-1squared opened 2 years ago

l-1squared commented 2 years ago

Especially TestNG cannot run in parallel with JGiven using injected stages, due to its lifecycle strategy. It would be nice to create a proxy for TestNG and by Extension JUnit5 to support those two testing frameworks more completely.

Follow-up for #829

adrian-herscu commented 1 year ago

Trying to get around the parallel dataprovider limitation that JGiven has with its TestNG integration...

In my scenario class defined stage fields as following (without using the @ScenarioStage annotation, which we all know it does not work well with parallel dataproviders):

    protected ThreadLocal<ElasticSearchFixtures<?>>  elasticSearchFixtures = new ThreadLocal<>();
    // and similar for ElasticSearchActions and ElasticSearchVerifications stages

and initialization methods, like this:

    protected ElasticSearchFixtures<?> given(
        final ElasticSearchFixtures<?> fixtures) {
        elasticSearchFixtures.set(fixtures);
        return fixtures;
    }

then, in scenario methods, I used these like this:

        given(new ElasticSearchFixtures<>())
            .elastic_search(configuration().elasticSearchClient())
            .and().indexed_by(configuration().elasticSearchIndex())
            .and().storing(JsonNode.class);

It all compiles fine, but fails with NPE because the fields in ElasticSearchActions and ElasticSearchVerifications are not injected.

I am not familiar with the injection mechanism used by JGiven, perhaps you can suggest something?

l-1squared commented 1 year ago

Do you have a more comprehensive sample? I am failing to understand, where these ElasticSearchActions and ElasticSearchVerifications are in the first place... Are these supposed to be scenario states?

adrian-herscu commented 11 months ago

Do you have a more comprehensive sample? I am failing to understand, where these ElasticSearchActions and ElasticSearchVerifications are in the first place... Are these supposed to be scenario states?

see #1469 -- both are about how to use multiple stages in a parallel testing mode