JS JVM multi project unit tests

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()
    }
}

To compile common tests you need to use test-metadata goal of kotlin-maven-plugin.

Note that the common module doesn’t produce any executable binaries, so you need to introduce platform modules for JVM and JS implementing that common module to get something you can run.

Have you already managed to run tests as if they were in separate modules without any shared sources?

The problem remains: The tests in the share project cannot be “compiled” because the assert methods are not found.

I’m sorry I just realised that during the compilation of the JVM project, I get the errors:

[ERROR] /home/sandro/projects/viseon/openorca/share/src/test/kotlin/ch/viseon/openOrca/share/Test.kt: (3, 20) Unresolved reference: assertEquals
[ERROR] /home/sandro/projects/viseon/openorca/share/src/test/kotlin/ch/viseon/openOrca/share/Test.kt: (27, 5) Unresolved reference: assertEquals 
....

I wrote some JSON parsing code, which is shared between JVM and JS which works great and I tried to move the JS test (run with Karma) to the share project.

on a side note: Would you recomand switching to the gradle plugins instead of maven? I saw the blogpost from yesterday introducing the gradle-frontend-plugin which generates all the config files for karma, package.json etc.

On a another side note: IDEA has some problems processing this project: For example, if I click “run tests”, the JVM projects doesn’t compile because its missing (or can’t “see” in a lack of a better word) the shared code. I saw in the kotlin project facet setting that “common” is experimental - is there an rough ETA when this will be improved?

Thanks for your reply, its very much appreciated.

I solved my issue: The JVM project did not have a dependency to kotlin-test-junit.