Hi!
I have an annotation processor library that I am very keen to get working for Kotlin, however I have hit a snag in terms of my unit testing. I would really appreciate if someone could give me some advice.
My current unit testing implementation uses Google’s compile-testing library. I create input and output classes and store them in the resources directory. Then during the unit test, the compile-testing library compiles the input java class, executes the annotation processor and then compares the generated classes against the output class from the resources directory.
Here is an example (from my project) of what I am referring to:
Unit test class
Resources (Input and output classes)
This is working great for all my current java based unit tests. However I’m hoping to write some unit tests that use Kotlin classes.
Unfortunately this does not appear to be that easy, as the compile-testing library is first and foremost a Java specific library (I don’t see any mention of Kotlin on their project)
At the moment I get the following issue:
java.lang.IllegalArgumentException: Compilation unit is not of SOURCE kind: “/C:/dev/gsonpath/gsonpath-compiler/build/resources/test/adapter/auto/field_types/primitives/valid/TestValidPrimitives.kt”
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:137)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:107)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:64)
at com.google.testing.compile.Compilation.compile(Compilation.java:69)
at com.google.testing.compile.JavaSourcesSubject$CompilationClause.compilesWithoutError(JavaSourcesSubject.java:281)
The problem is fairly obvious that the incorrect compiler is being used.
Has anyone come across this issue before and solved it? I have had a look at a few other annotation processors (such as DBFlow), and they do not write unit tests in this manner.