playframeworksbtscoverage

SBT : Overriding default test task


In our play project, we are running scoverage coverageReport using the following command:

sbt clean coverage test coverageReport

Instead of the explicit coverageReport goal , I want to run the report as part of test goal itself , something like

sbt test

should automatically run the coverageReport as well

I am a newbie for sbt/play so I am trying something like

test = test ++ ScoverageKeys.coverageReport

and

  test in Test := {
    (test in Test).value
    ScoverageKeys.coverageReport.value
  }

and few other options but nothing worked.

Could some one let me know how to override default test config so that it runs the coverage and coverageReport too in addition to running tests?

It would be nice if test goal triggers coverage before starting tests and coverageReport after finishing tests,

I have also tried adding a command alias in MicroService.scala and in plugins.sbt as below but it didnt work even.

addCommandAlias("test", "coverage test coverageReport")

Any ideas on how to make it work would be much appreciated.

Thanks

Suresh


Solution

  • I was able to solve this using the below snippet

      .settings(
        test in Test := Def.sequential(
          test in Test,
          ScoverageKeys.coverageReport.toTask
        ).value
      )