MUnit is a lightweight testing library. It provides a single style for writing tests, a style that can be learned quickly.
Despite its simplicity, MUnit has useful features such as:
- assertions to verify the behavior of the program
- fixtures to ensure that the tests have access to all the necessary resources
- asynchronous support, for testing concurrent and distributed applications.
MUnit produces actionable error reports, with diff and source location, to help you quickly understand failures.
Testing is essential for any software development process because it helps catch bugs early, improves code quality and facilitates collaboration.
You can require the entire toolkit in a single line:
//> using toolkit latest
MUnit, being a testing framework, is only available in test files: files in a test
directory or ones that have the .test.scala
extension. Refer to the Scala CLI documentation to learn more about the test scope.
Alternatively, you can require just a specific version of MUnit:
//> using dep org.scalameta::munit:1.0.3
In your build.sbt file, you can add the dependency on toolkit-test:
lazy val example = project.in(file("."))
.settings(
scalaVersion := "3.3.4",
libraryDependencies += "org.scala-lang" %% "toolkit-test" % "0.1.7" % Test
)
Here the Test
configuration means that the dependency is only used by the source files in src/test
.
Alternatively, you can require just a specific version of MUnit:
libraryDependencies += "org.scalameta" %% "munit" % "1.0.3" % Test
In your build.sc file, you can add a test
object extending Tests
and TestModule.Munit
:
object example extends ScalaModule {
def scalaVersion = "3.3.4"
object test extends Tests with TestModule.Munit {
def ivyDeps =
Agg(
ivy"org.scala-lang::toolkit-test:0.1.7"
)
}
}
Alternatively, you can require just a specific version of MUnit:
ivy"org.scalameta::munit:1.0.3"
Contributors to this page:
Contents
- Introduction
- Testing with MUnit
- How to write tests?
- How to run tests?
- How to run a single test?
- How to test exceptions?
- How to write asynchronous tests?
- How to manage the resources of a test?
- What else can MUnit do?
- Working with files and processes with OS-Lib
- How to read a directory?
- How to read a file?
- How to write a file?
- How to run a process?
- What else can OS-Lib do?
- Handling JSON with uPickle
- How to access values inside JSON?
- How to modify JSON?
- How to deserialize JSON to an object?
- How to serialize an object to JSON?
- How to read and write JSON files?
- What else can uPickle do?
- Sending HTTP requests with sttp
- How to send a request?
- How to construct URIs and query parameters?
- How to send a request with a body?
- How to send and receive JSON?
- How to upload a file over HTTP?
- What else can sttp do?
- Building web servers with Cask
- How to serve a static file?
- How to serve a dynamic page?
- How to handle query parameters?
- How to handle user input?
- How to use websockets?
- How to use cookies and decorators?