score:0

I have figured it out. We can use variables in buld.sbt and use it to construct the directory name.

val format = new SimpleDateFormat("dd-MM-yy-hhmmss")
val timeStamp : String = format.format(Calendar.getInstance().getTime())
val resultDirectory : String = "target/test-reports/"+timeStamp

testOptions in Test ++= Seq(Tests.Argument(TestFrameworks.ScalaTest, "-o"), Tests.Argument(TestFrameworks.ScalaTest, "-h", resultDirectory))
libraryDependencies +=  "org.pegdown" % "pegdown" % "1.6.0" % "test"

I tried this earlier but did not work. The reason is every time you change the build.sbt file you need to reload the sbt shell, which I did not earlier.

score:1

Try

libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0",
testOptions in Test ++= Seq(
  Tests.Argument(TestFrameworks.ScalaTest, "-o"), 
  Tests.Argument(TestFrameworks.ScalaTest, "-h", s"target/test-reports-$testDirTimestamp")
)

def testDirTimestamp = {
  import java.time.LocalDateTime
  import java.time.format.DateTimeFormatter
  LocalDateTime.now.format(DateTimeFormatter.ofPattern("yyyy-MM-ddHHmmss"))
}

which after executing sbt test should create reports under

target/test-reports-2019-07-02074159

Related Query

More Query from same tag