JGiven icon indicating copy to clipboard operation
JGiven copied to clipboard

Create proxy to allow JGiven to run with Class lifecycles

Open l-1squared opened this issue 3 years ago • 3 comments

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

l-1squared avatar May 11 '22 04:05 l-1squared

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?

adrian-herscu avatar Sep 27 '23 12:09 adrian-herscu

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?

l-1squared avatar Sep 29 '23 10:09 l-1squared

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

adrian-herscu avatar Dec 11 '23 01:12 adrian-herscu