micronaut-projects / micronaut-aws

Projects specific to integrating Micronaut and Amazon Web Services (AWS)
Apache License 2.0
85 stars 79 forks source link

Failing test for issue 1870 #1984

Closed timyates closed 8 months ago

timyates commented 9 months ago

When annotated with @MicronautLambdaTest, this test fails.

It is because the EagerSingleton inside the Hander and the Test are 2 different mocks.

When this test is run with @MicronautTest then it passes...

It must be something to do with Environments, as using

@MicronautTest(environments = {Environment.FUNCTION, MicronautLambdaContext.ENVIRONMENT_LAMBDA, Environment.TEST})

Also fails with the same issue...

sonarcloud[bot] commented 9 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

timyates commented 9 months ago

Weirdly the same test in Micronaut-test doesn't fail when I change the environments...

So it must be some interaction happening in this aws module...

Found a workaround which is to annotate the field with @MockBean instead of @Inject as in this test in micronaut-test

https://github.com/micronaut-projects/micronaut-test/blob/2c6b1d198ab362f081a2874e2bc9e28095f1e9ca/test-junit5/src/test/java/io/micronaut/test/junit5/MathMockFieldCollaboratorTest.java#L22-L21

timyates commented 8 months ago

Superseded by https://github.com/micronaut-projects/micronaut-aws/pull/2007