Annotation Type JavacCompilerTest


@API(since="0.0.1", status=STABLE) @ArgumentsSource(JavacCompilersProvider.class) @DisabledInNativeImage @Documented @ParameterizedTest(name="for compiler \"{0}\"") @Retention(RUNTIME) @Tag("java-compiler-testing-test") @Tag("javac-test") @Target({ANNOTATION_TYPE,METHOD}) @TestTemplate public @interface JavacCompilerTest
Annotation that can be applied to a JUnit parameterized test to invoke that test case across multiple compilers, each configured to a specific version in a range of Java language versions.

This will also add the "java-compiler-testing-test" tag and "javac-test" tags to your test method, meaning you can instruct your IDE or build system to optionally only run tests annotated with this method for development purposes. As an example, Maven Surefire could be instructed to only run these tests by passing -Dgroup="javac-test" to Maven.

If your build is running in a GraalVM Native Image, then this test will not execute, as the Java Compiler Testing API is not yet tested within Native Images.

For example, to run a simple test on Java 11 through 17 (inclusive):


   class SomeTest {
     @JavacCompilerTest(minVersion = 11, maxVersion = 17)
     void canCompileHelloWorld(JctCompiler> compiler) {
       // Given
       try (var workspace = Workspaces.newWorkspace()) {
         workspace
            .createFile("org", "example", "HelloWorld.java")
            .withContents("""
              package org.example;

              public class HelloWorld {
                public static void main(String[] args) {
                  System.out.println("Hello, World!");
                }
              }
            """);

         var compilation = compiler.compile(workspace);

         assertThat(compilation)
             .isSuccessfulWithoutWarnings();
       }
     }
   }
 
Since:
0.0.1
Author:
Ashley Scopes