By Alvin Alexander. Last updated: January 22, 2021
Here’s a quick example of how to use Minitest with a Scala 3.0-M3 sbt project. First, here’s an example sbt build.sbt file:
val scala3Version = "3.0.0-M3" lazy val root = project .in(file(".")) .settings( name := "scala3-simple", version := "0.1.0", scalaVersion := scala3Version, libraryDependencies += "io.monix" %% "minitest" % "2.9.2" % "test", testFrameworks += new TestFramework("minitest.runner.Framework") ) scalacOptions ++= Seq( "-deprecation", // emit warning and location for usages of deprecated APIs "-explain", // explain errors in more detail "-explain-types", // explain type errors in more detail "-feature", // emit warning and location for usages of features that should be imported explicitly "-indent", // allow significant indentation. "-new-syntax", // require `then` and `do` in control expressions. "-print-lines", // show source code line numbers. "-unchecked", // enable additional warnings where generated code depends on assumptions "-Ykind-projector", // allow `*` as wildcard to be compatible with kind projector "-Xfatal-warnings", // fail the compilation if there are any warnings "-Xmigration", // warn about constructs whose behavior may have changed since version "-source:3.1" )
Next, here’s the syntax for a Minitest unit-testing file that you’d put under src/test/scala:
import minitest._ // https://github.com/monix/minitest // https://github.com/sbt/test-interface object MySimpleSuite extends SimpleTestSuite { test("should be") { assertEquals(2, 1 + 1) } test("should not be") { assert(1 + 1 != 3) } test("should throw") { class DummyException extends RuntimeException("DUMMY") def test(): String = throw new DummyException intercept[DummyException] { test() } () } test("test result of") { assertResult("hello world") { "hello" + " " + "world" } } }
That code comes directly from the Minitest docs.