Search code examples
scalatest

How can scalatest-maven-plugin be run outside of maven Test phase?


We have created a project which is an end to end system test harness written in Scala

The harness code and testcases both live inside of Main

When we run the maven 'test' phase, the tests are recognised, run, and results with xml are written to surefire directory.

However, if we just click run (shift + f10) then the tests are recognised, run, but it seems the scalatest-maven-plugin does not run, and no external results/xml are produced.

How can we get the plugin to run when the project is run? Without using Maven 'test' phase?

I've tried changing <goal>compile</goal> for the plugin, but 'compile' is not accepted.

(It should be noted, our end goal is to have the compiled project run from databricks as a job calling the test harness jar, and for the plugin to be utilised to produce the report xml for devops to pickup)


Solution

  • Calling the scalatest Runner with the appropriate parameters should do the job.
    Please check the Runner options carefully in order to adapt the call for your specific needs.
    A short example:

    val return = org.scalatest.tools.Runner.run(
    Array("-o"
    , "-u", "/tmp/logs"
    , "-s", "alpha.beta.gamma.YourTestClass"
    , "-R", "/path-to/test.jar"))