Write tests
Write unit and integration tests, tag them, and read the coverage they produce.
Forge splits tests in two by tag. Unit tests run in the Gradle test JVM. Integration tests need a running CATIA Magic, so they run in a JVM Forge forks for them.
configure.testing defaults on, so most projects write nothing. That flag makes Forge supply the
JUnit 5 stack — the JUnit BOM 5.11.3, junit-jupiter and
junit-platform-launcher — so a project declares no JUnit dependency of its own. The generated
integration runner drives the launcher directly, which is why the launcher joins the stack rather
than staying a runtime detail. It also strips the JUnit that CATIA Magic bundles in lib/, along
with classpath.jar, off the test classpath. Left in place, that older stack shadows the curated one
and breaks the launcher.
Tag every test
@Tag("UnitTest")
class VersionRulesTest {
@Test
fun `rejects a version below the minimum`() { … }
}| Tag | Meaning |
|---|---|
@Tag("UnitTest") | Runs without CATIA Magic |
@Tag("IntegrationTest") | Requires CATIA Magic to launch |
The tags are what select the tests, so an untagged test runs in neither task.
Write an integration test
Tag the test and extend it with Dassault's JUnit 5 extension. Nothing else is required:
@Tag("IntegrationTest")
@ExtendWith(MagicDrawApplication::class)
class ProfileInstallationTest {
@Test
fun `the profile loads into a new project`() { … }
}Write no test suite, and write no shutdown code. Forge generates a runner that owns the
fork, discovers the tagged tests, writes the report, and releases the licence seat. A @Suite class
with an @AfterSuite shutdownMagicDraw() method conflicts with the generated runner, which already
does that work. Delete it.
Integration testing explains why the fork is needed: the
extension leaves the application running, only a full shutdown releases the licence seat, and that
shutdown calls System.exit().
Open a shipped archive
A test that opens a .mdzip the resource ships reads it from src/main/assembly/. Forge passes the
absolute path of that directory to both test JVMs as the system property
forge.integration.assemblyDir, so the build script wires no path of its own:
val assembly = File(checkNotNull(System.getProperty("forge.integration.assemblyDir")))
val library = assembly.resolve("modelLibraries/Optics_Library.mdzip")Renaming a shipped archive then touches the test alone. A unit test can read the archive as a zip
with no project open; an integration test can open it as a project in the running tool. The
directory's content is an input of test, so adding or editing a file under src/main/assembly/
re-runs the unit tests.
Run them
./gradlew test
./gradlew integrationTesttest runs the UnitTest-tagged tests. integrationTest runs the IntegrationTest-tagged ones in
a forked JVM on the CATIA Magic JRE, with the tool's own vm.options applied.
integrationTest exists only when a CATIA Magic installation path is configured, which
installCatiaMagic records. A project without an installation gets no such task, and the
configuration log says so.
The task ignores the fork's exit code on purpose. Success comes from the JUnit XML report the runner
writes, which is what keeps the licence-releasing System.exit() from failing a passing run. A run
where no test executed fails the task rather than passing silently.
That failure applies to a project that owns an integration suite. A project whose test sources carry
no @Tag("IntegrationTest") skips the task instead, forking no JVM and taking no licence, so a
project that has not written its first integration test still builds. The two cases are told apart
before the fork, by scanning the test sources for the tag. A tag reached through a meta-annotation or
a constant reads as absent and skips the task; write the annotation literally to have it run.
Coverage
Both tasks produce a JaCoCo execution file, since configure.jacoco defaults on and Forge applies
the jacoco plugin itself:
./gradlew jacocoTestReport
./gradlew jacocoTestCoverageVerificationcheck depends on both, so ./gradlew build runs them too. The reports feed tools such as
SonarQube or Qodana. See Configure code quality.
Opt out
com.mbseconsulting.forge.configure.testing=falseForge then configures no test task, supplies no JUnit stack, and leaves the CATIA Magic jars on the test classpath untouched. The project owns its test setup entirely.