I have a js-jvm multi project setup with maven.
I’d like to execute unit tests from my share (contains code for JVM and JS) once for JVM and once for JS.
To achieve this I placed my test classes in /share/test/kotlin.
The problem is, that they don’t compile because the tests don’t see assertEquals()
methods
Reported compiler problem:
[ERROR] /home/sandro/projects/viseon/openorca/share/src/test/kotlin/ch/viseon/openOrca/share/Test.kt:[3,20] Unresolved reference: assertEquals
The POM file for project “share” looks like this:
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-common</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-common</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>metadata</id>
<goals>
<goal>metadata</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<forceCreation>true</forceCreation>
<archive>
<forced />
<manifestEntries>
<Built-By>${user.name}</Built-By>
<Implementation-Vendor>JetBrains s.r.o.</Implementation-Vendor>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
<execution>
<id>pack-meta</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The unit test is structured like this:
Code in project “share”:
abstract class AbstractJsonCodecTest {
private fun assertParsedCommand(commandData: CommandData) {
val (command, json) = encodeAndDecodeCommand(commandData)
assertEquals(commandData, command, "comparison failed. Produced json: \n$json")
}
open fun decodeCreateCommand() {
assertParsedCommand(SharedTestData.createModelCommand())
}
}
A JVM implementation:
Code in project “jvm”
class JsonCodecTest : AbstractJsonCodecTest() {
@Test
override fun decodeCreateCommand() {
super.decodeCreateCommand()
}
}