zamblauskas / sbt-examplestest   0.3.0

MIT License GitHub

SBT plugin to generate unit tests for code examples

Scala versions: 2.12
sbt plugins: 1.0

scaladex-badge ci-badge


SBT plugin to generate unit tests for code examples in markdown (e.g. README) files.


Package is available at Maven Central. Check for the latest version and add to your project/plugins.sbt:

addSbtPlugin("io.github.zamblauskas" % "sbt-examplestest" % "<latest_version>")
version SBT scalatest munit-cats-effect-3
0.1.1 0.13 3.0.4
0.1.2 1.x 3.0.4
0.2.0+ 1.x 3.1.0 1.0.3

Plugin will be enabled by default. It will detect the testing library used in the project and select corresponding code generator. Then it will find all .md files in the base directory, generate unit test code for every Scala block (marked as ``` scala) and put it in target/scala-<version>/src_managed/test. Tests will be run during sbt test.


If you have

``` scala val foo = "bar" foo shouldBe "bar" ```

plugin will create target/scala-2.11/src_managed/test/READMETest.scala:

import org.scalatest.{FunSpec, Matchers}

class READMETest extends FunSpec with Matchers {
  describe("README") {
    it("code block #0") {
val foo = "bar"
foo shouldBe "bar"


Defaults should work for most of the projects, but you can change a few SBT keys if needed.

// path to markdown files
examplesTestInputFiles := (baseDirectory.value * "*.md").filter(_.isFile).get

// code block types the plugin generates unit tests for
examplesTestCodeBlockTypes := Seq("scala")