springspring-bootspring-testspring-native

How can I exclude test classes when running nativeTest?


I have a Spring boot 3.1.4 application that has some tests that use things like @DataJpaTest/@WebMvcTest/etc that use mocking & whatnot which aren't supported when running in native test mode.

Is there a way I can exclude these tests from running when running the nativeTest maven profile?

I do want them to run in JVM mode though.


Solution

  • You can mark test with via the @EnabledInNativeImage and @DisabledInNativeImage annotations.

    Example to not run a test when running nativeTest profile:

    @Test
    @DisabledInNativeImage
    void neverWithinNativeImage() {
        // ...
    }