TNG/JGiven

Nested stages are not reused / Spring / @JGivenStage / @ScenarioStage

Closed this issue · 4 comments

Given the following hierarchy.

  1. ScenarioIntTest has field SharedStageA stageA
  2. ScenarioIntTest has field SharedStageB stageB
  3. SharedStageB has field SharedStageA stageA

The stageA field inside SharedStageB is not initialized.

As far as I can tell from the documentation this shall work.
Am I doing something wrong or not using nested stages correctly?

Simplified code

@EnableJGiven
class ScenarioIntTest extends SpringRuleScenarioTest<ScenarioGiven, ScenarioWhen, ScenarioThen> { 
     @ScenarioStage
    SharedStageA stageA;

   @ScenarioStage
    SharedStageB stageB;

    some_test() {

        stageA.and().a_resource([...]);

        stageB.and().b_resource([...]);
    }
}


@JGivenStage
class SharedStageA {

   @ProvidedScenarioS

    a_resource([...]) {
       [...]
    }

    other_a_resource([...]) {
       [...]
    }
}

/**
 * B depends on A 
 */ 
@JGivenStage
class SharedStageB {

    @ScenarioSage
    SharedStageA stageA;   // << this is not injected/is null

    b_resource([...]) {
          stageA.and().other_a_resource([...])
    }

}

Hi, thanks for reporting the issue. I will probably have a look into it next week.

Dear @albertmatyi,

unfortunately I cannot reproduce your issue. This test that I fashioned from your simplified example works fine within my JUnit4 -spring package ( and the corresponding JUnit5 test works fine too).

package com.tngtech.jgiven.integration.spring.test;

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.ScenarioStage;
import com.tngtech.jgiven.integration.spring.EnableJGiven;
import com.tngtech.jgiven.integration.spring.JGivenStage;
import com.tngtech.jgiven.integration.spring.SpringRuleScenarioTest;
import com.tngtech.jgiven.integration.spring.config.TestSpringConfig;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;

@EnableJGiven
@ContextConfiguration( classes = TestSpringConfig.class )
public class NestedTest extends SpringRuleScenarioTest<SimpleTestSpringSteps,SomeWhen,SomeThen> {
    @ScenarioStage
    SharedStageA stageA;

    @ScenarioStage
    SharedStageB stageB;


    @Test
    public void some_test() {

        stageA.and().a_resource();

        stageB.and().b_resource();
    }
}


@JGivenStage
class SharedStageA extends Stage<SharedStageA> {

    SharedStageA a_resource() {
        return self();
    }

    SharedStageA other_a_resource() {
        return self();
    }
}

/**
 * B depends on A
 */
@JGivenStage
class SharedStageB extends Stage<SharedStageB> {

    @ScenarioStage
    SharedStageA stageA;   // << this is not injected/is null

    SharedStageB b_resource() {
        stageA.and().other_a_resource();
        return self();
    }

}

Did you strip your example down too much, did you manage to resolve the issue in the meantime, or is there something else that I am missing?

@albertmatyi can this be closed?

No further input from reporter.