Home

Awesome

Scala Test-State

Test stateful stuff statelessly, and reasonably.

Build Status

Contents

What is this?

Firstly, a quick mention of what this is not:

  1. This is not a test framework. <br>Use it conjunction with ScalaTest, Specs2, μTest, etc.

  2. This is not a property testing library. <br>Use it conjunction with ScalaCheck, Nyaya, ScalaProps, etc.

Ok, so what is this? This is a library that:

  1. Lets you write pure, immutable, referentially-transparent tests that verify stateful, effectful code or data.

  2. Encourages composability of test concepts such as invariants/properties, pre/post conditions, dynamic actions/assertions, and more.

  3. Makes test failure and inspection easy to comprehend.

Uses

Features

How does this work?

The key is to take observations of anything relevant in the stateful test subject. Observations are like immutable snapshots. They capture what the state was at a particular point in time. Once an observation is captured, assertions are performed on it.

Optionally, you can specify some kind of test-only state that you modify as you test, and use to ensure the real-world observations are what you expect. <br>For example, if you're testing a bank account app, you could maintain your own expected balance such that when you instruct the app to make a deposit, you add the same amount to your state. You could then add an invariant that whenever the balance is shown in the app, it matches the expected state balance.

This is a (simplified) model of how tests are executed:

concept

When retries are enabled, then test execution is like this.

How do I use this?

Modules

ModuleDescriptionJVMJS
coreThe core module.JVMJS
dom-zipperStandalone utility for observing web DOM with precision with conciseness.<br>This is the base API; concrete implementations below.JVMJS
dom-zipper-jsoupDOM zipper built on Jsoup.JVM
dom-zipper-seleniumDOM zipper built on Selenium.<br>Also comes with a fast version with uses Jsoup for nearly all operations which is 5-50x faster.<br>See doc/SELENIUM.md.JVM
dom-zipper-sizzleDOM zipper built on Sizzle.JS
ext-catsExtensions for Cats.JVMJS
ext-nyayaExtensions for Nyaya.JVMJS
ext-scalajs-reactExtensions for scalajs-react.JS
ext-seleniumExtensions for Selenium.JVM

Examples

Support

If you like what I do —my OSS libraries, my contributions to other OSS libs, my programming blog— and you'd like to support me, more content, more lib maintenance, please become a patron! I do all my OSS work unpaid so showing your support will make a big difference.