-
-
Notifications
You must be signed in to change notification settings - Fork 6
@Introspect Configuration
⚠️ This wiki is no longer maintained. Please refer to https://github.com/Pante/elementary/tree/master/docs instead.
In prehistoric times before the invention of @Introspect
, ancient developers that tested annotation processors had to specify their test cases either in a separate source file or in an inline string. Those were dark times indeed, for specifying test cases in a separate test file meant splitting their focus between two files, the test file and the test cases file. We shall not dwell any further on test cases in inline strings either since writing one was frustrating enough to induce a stroke. Salvation arrived in the form of the @Introspect
annotation which allowed a test file to inspect it's own Element
and TypeMirror
representation inside tests. This meant that test cases could finally be declared in the same file as a test suite.
Unfortunately, to achieve this, the test sources need to be copied from the original folder to the output folder. This can usually be achieved by adjusting the build tool's configuration. Below, we provide examples for Maven
and Gradle
.
In the <build/>
section of a project's pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/test-classes/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/test/java/</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
In the project's build.gradle:
task copyTestSources(type: Copy) {
from file("${project.projectDir}/src/test/java/")
into file("${project.projectDir}/build/classes/java/test/")
}
test {
dependsOn 'copyTestSources'
}