Setup a KF Test Suite

A KF test suite can be executed when building a Foundation Library or an Add-On library, and usually extends the tests written for the default library test suite to verify the behavior of this library when its APIs are exposed by a Kernel.

A KF test suite is composed of a set of KF tests, each KF test itself is a minimal Multi-Sandbox Executable composed of a Kernel and zero or more Features.

Enable the Test Suite

In an existing library project:

  • Create the src/test/resources/projects directory.

  • Follow the instructions to setup a testsuite on the Simulator.

  • In the build script file, replace the line:

    microej.useMicroejTestEngine(this)
    

by:

microej.useMicroejTestEngine(this, TestTarget.EMB, TestMode.PROJECT)
  • Add the import statements at the beginning of the file:

    import com.microej.gradle.plugins.TestMode
    import com.microej.gradle.plugins.TestTarget
    
  • Add the required properties as follows:

    val test by getting(JvmTestSuite::class) {
       microej.useMicroejTestEngine(this, TestTarget.EMB, TestMode.PROJECT)
    
       targets {
          all {
             testTask.configure {
                doFirst {
                      systemProperties = mapOf(
                         "microej.testsuite.properties.microejtool.deploy.name" to "deployToolBSPRun",
    
                         // Configure the TCP/IP address and port if the VEE Port Run script does not redirect execution traces
                         "microej.testsuite.properties.testsuite.trace.ip" to "localhost",
                         "microej.testsuite.properties.testsuite.trace.port" to "5555",
                         // Tell the testsuite engine that the VEE Port Run script redirects execution traces.
                         // Uncomment this line and comment the 2 lines above if the VEE Port supports it.
                         //"microej.testsuite.properties.launch.test.trace.file" to "true"
                      )
                }
             }
          }
       }
    }
    

Add a KF Test

A KF test is a structured directory placed in the src/test/resources/projects directory in SDK 6, or in the src/test/projects directory in SDK 5. The creation of a KF is done as follows:

  • In the src/test/resources/projects directory, create a new directory newTest for the KF test.

  • In the src/test/java folder, create a new Interface with the following content:

import org.junit.Test;

public interface MyTest {

   @Test
   void newTest();
}

Note

The name of a KF test is free. For each KF test, a method with the same name and annotated with @Test must be defined in the Java Interface.

  • Within the newTest directory, create the sub-projects:

    • Create a new kernel directory and create a Kernel. The Kernel must depend on your Library project:

    implementation("org.example:myLibrary")
    

    Note

    The Library project is used as an included build when running one of its KF tests. Therefore, it is not mandatory to specify the dependency version here.

    • Create a new app directory and create an Application.

    • Create a settings.gradle.kts file and add the following content:

    include("kernel", "app")
    

Each KF test must contain a Kernel project named kernel. If the KF Test also contains one or more Feature projects, their names must be prefixed by app.

The KF Test Suite structure shall be similar to the following figure:

KF Test Suite Structure

KF Test Suite Overall Structure

KF Test Suite Options (SDK 5 only)

It is possible to configure the same options defined by Test Suite Options for the KF test suite, by using the prefix microej.kf.testsuite.properties instead of microej.testsuite.properties.