Skip to content

Document that testing with ApplicationContextRunner in a native image is not supported #34007

@ruben-garciapariente

Description

@ruben-garciapariente

Hello,

I am using Spring Boot 3.0.2. I have tried to compile natively with mvn -PnativeTest clean test a test that uses the class ApplicationContextRunner. Without adding any 'RuntimeHints' it returns me the following error:

Failures (1): JUnit Jupiter:ContextRunnerTests:testContextRunner() MethodSource [className = 'com.example.errorcontextrunner.ContextRunnerTests', methodName = 'testContextRunner', methodParameterTypes = ''] => com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.springframework.context.ConfigurableApplicationContext, interface org.springframework.boot.test.context.assertj.AssertableApplicationContext] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options. org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89) org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.proxy.DynamicProxySupport.getProxyClass(DynamicProxySupport.java:171) java.base@17.0.5/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:47) java.base@17.0.5/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037) org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider.get(ApplicationContextAssertProvider.java:112) org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.createAssertableContext(AbstractApplicationContextRunner.java:389) org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.consumeAssertableContext(AbstractApplicationContextRunner.java:362) org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.lambda$run$0(AbstractApplicationContextRunner.java:341) org.springframework.boot.test.util.TestPropertyValues.lambda$applyToSystemProperties$1(TestPropertyValues.java:174) org.springframework.boot.test.util.TestPropertyValues.applyToSystemProperties(TestPropertyValues.java:188) [...] 

It can be replicated using the following example https://github.com/ruben-garciapariente/error-context-runner-native

If I add the "RuntimeHints" for the application configuration class it returns the following error (example at https://github.com/ruben-garciapariente/error-context-runner-native/tree/2e07cbca3b716fc871c663593b0f326b5aabdf3a):

Failures (1): JUnit Jupiter:ContextRunnerTests:testContextRunner() MethodSource [className = 'com.example.errorcontextrunner.ContextRunnerTests', methodName = 'notWeb', methodParameterTypes = ''] => java.lang.IllegalStateException: Unable to read meta-data for class com.example.errorcontextrunner.AutoConfig org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationMetadata(AutoConfigurationSorter.java:237) org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationValue(AutoConfigurationSorter.java:219) org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAfter(AutoConfigurationSorter.java:198) org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClasses.getClassesRequestedAfter(AutoConfigurationSorter.java:143) org.springframework.boot.autoconfigure.AutoConfigurationSorter.doSortByAfterAnnotation(AutoConfigurationSorter.java:90) [...] Caused by: java.io.FileNotFoundException: class path resource [com/example/errorcontextrunner/AutoConfig.class] cannot be opened because it does not exist org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211) org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:54) org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48) org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) [...] 

Apparently there is no support for native compilation of an ApplicationContextRunner test. I have reviewed the following documentation and I have not found that it is indicated that it is not supported:

Thank you very much

Metadata

Metadata

Assignees

No one assigned

    Labels

    theme: aotAn issue related to Ahead-of-time processingtype: documentationA documentation update

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions