You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
When there are test classes with the same name in different packages that have independent MergedContextConfiguration, the AOT test code generation fails.
For example, if MyTest class exists in com.example.foo and com.example.bar packages, the following exception is thrown.
java.lang.IllegalArgumentException: context with id 'MyTestContextInitializer' already exists
at org.springframework.aot.context.bootstrap.generator.infrastructure.DefaultBootstrapWriterContext.fork(DefaultBootstrapWriterContext.java:129)
at org.springframework.aot.context.bootstrap.generator.infrastructure.DefaultBootstrapWriterContext.fork(DefaultBootstrapWriterContext.java:123)
at org.springframework.aot.test.context.bootstrap.generator.TestContextAotProcessor.generateTestContext(TestContextAotProcessor.java:107)
at org.springframework.aot.test.context.bootstrap.generator.TestContextAotProcessor.generateTestContexts(TestContextAotProcessor.java:78)
at org.springframework.aot.test.build.TestContextBootstrapContributor.contribute(TestContextBootstrapContributor.java:61)
at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:89)
at org.springframework.aot.build.BootstrapCodeGenerator.generate(BootstrapCodeGenerator.java:68)
at org.springframework.aot.test.build.GenerateTestBootstrapCommand.call(GenerateTestBootstrapCommand.java:87)
at org.springframework.aot.test.build.GenerateTestBootstrapCommand.call(GenerateTestBootstrapCommand.java:45)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine.execute(CommandLine.java:2078)
When there are test classes with the same name in different packages that have independent
MergedContextConfiguration
, the AOT test code generation fails.For example, if
MyTest
class exists incom.example.foo
andcom.example.bar
packages, the following exception is thrown.This is because when a
MergedContextConfiguration
is different,TestContextConfigurationDescriptorFactory
creates differentTestContextConfigurationDescriptor
s. When this descriptor contains a single test class, it uses the test class name(MyTestContextInitializer
in this case) as a map key:https://github.com/spring-projects-experimental/spring-native/blob/d8adb77be77da3f07a18dc95d54a8fec839edb0a/spring-aot-test/src/main/java/org/springframework/aot/test/context/bootstrap/generator/TestContextAotProcessor.java#L149-L153
https://github.com/spring-projects-experimental/spring-native/blob/d8adb77be77da3f07a18dc95d54a8fec839edb0a/spring-aot-test/src/main/java/org/springframework/aot/test/context/bootstrap/generator/TestContextAotProcessor.java#L106-L107
Then, in the
fork
method, the unique check(this.allContexts.containsKey(id))
) is failing since the test classes in both test descriptors have the same name:https://github.com/spring-projects-experimental/spring-native/blob/2833e110534bce100820faac881932ca0ae5535e/spring-aot/src/main/java/org/springframework/aot/context/bootstrap/generator/infrastructure/DefaultBootstrapWriterContext.java#L127-L134
In this case, the key needs to be a unique valid java class name.
The text was updated successfully, but these errors were encountered: