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

Context is not propagated in Junit5 nested class #1417

Closed
eximius313 opened this issue Oct 31, 2018 · 12 comments
Closed

Context is not propagated in Junit5 nested class #1417

eximius313 opened this issue Oct 31, 2018 · 12 comments
Assignees
Labels
status/need-investigation This needs more in-depth investigation type/bug A general bug

Comments

@eximius313
Copy link

Expected behavior

Both tests pass

Actual behavior

Only test in main class pass

Steps to reproduce

Run the test:

@ExtendWith(SpringExtension.class)
@TestExecutionListeners(MockitoTestExecutionListener.class)
class ContextTest {

    @Nested
    class Nest {

        @Test
        void testContext() {
          StepVerifier.create(Mono.just(1).map(i -> i + 10),
          StepVerifierOptions.create().withInitialContext(Context.of("foo", "bar")))
              .expectAccessibleContext()
              .contains("foo", "bar")
              .then()
              .expectNext(11)
              .verifyComplete();
        }
    }

    @Test
    void testContext() {
      StepVerifier.create(Mono.just(1).map(i -> i + 10),
      StepVerifierOptions.create().withInitialContext(Context.of("foo", "bar")))
          .expectAccessibleContext()
          .contains("foo", "bar")
          .then()
          .expectNext(11)
          .verifyComplete();
    }
}

Reactor Core version

3.2.0.RELEASE

JVM version (e.g. java -version)

9.0.4

@eximius313
Copy link
Author

Ok, solved. You need to add ReactorContextTestExecutionListener.class to @TestExecutionListeners

@eximius313
Copy link
Author

False alarm, it made things even worse...

@eximius313 eximius313 reopened this Oct 31, 2018
@smaldini smaldini added the for/user-attention This issue needs user attention (feedback, rework, etc...) label Nov 5, 2018
@bsideup
Copy link
Contributor

bsideup commented Nov 6, 2018

Hi @eximius313,

Thanks for your report! I tried to run the code you provided but I did not observe any test failure, both are passing.

Could you please provide more information about your environment?
e.g. I see SpringExtension and Mockito's extension, which versions of both are you using?

Thank you!

@ghost
Copy link

ghost commented Nov 9, 2018

Hi @bsideup , thanks for your response.

We use spring-test 5.1.0.RELEASE and spring-boot-test:2.1.0.M4

The nested test fails with reason: java.lang.AssertionError: No propagated Context

@bsideup
Copy link
Contributor

bsideup commented Nov 9, 2018

@anilewek does it also fail if you update to the release version of spring-boot-test (2.1.0.RELEASE)?

@ghost
Copy link

ghost commented Nov 9, 2018

@bsideup yes, it still fails with the same error.

@bsideup bsideup self-assigned this Nov 12, 2018
@bsideup bsideup added type/bug A general bug status/need-investigation This needs more in-depth investigation and removed for/user-attention This issue needs user attention (feedback, rework, etc...) labels Nov 12, 2018
@bsideup
Copy link
Contributor

bsideup commented Nov 12, 2018

Ok, I was able to reproduce it, but only when 'org.springframework.security:spring-security-test' is added to the classpath.
@anilewek could you please confirm that you have it?

Meanwhile, I'll check with Spring Security folks why it happens.

@eximius313
Copy link
Author

I confim (I have it as transitive dependency)

@bsideup
Copy link
Contributor

bsideup commented Nov 12, 2018

Ok, @Nested is not the cause.

Reproduced with:

@ExtendWith(SpringExtension.class)
class ContextTest {

    @Test
    void testContext() {
        StepVerifierOptions stepVerifierOptions = StepVerifierOptions.create()
                .withInitialContext(Context.of("foo", "bar"));

        StepVerifier.create(Mono.just(1), stepVerifierOptions)
                .expectAccessibleContext()
                .contains("foo", "bar")
                .then()
                .verifyComplete();
    }
}

it works if you annotate test class with @TestExecutionListeners(MockitoTestExecutionListener.class) but fails without it. Will check why.

@eximius313 @anilewek it also means that you can temporary workaround the bug by annotating your nested class with @TestExecutionListeners(MockitoTestExecutionListener.class)

@eximius313
Copy link
Author

Thanks

@bsideup
Copy link
Contributor

bsideup commented Nov 14, 2018

Hi @eximius313,

Was about to follow up :)

I think we were able to identify the problem and the fix will be included in the next release.
Meanwhile, it would be nice if you can test it with a SNAPSHOT version:
https://projectreactor.io/docs/core/release/reference/index.html#_milestones_and_snapshots

Thanks!

@ghost
Copy link

ghost commented Dec 12, 2018

I can confirm that the error does not occur with version 3.2.3
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-investigation This needs more in-depth investigation type/bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants