• Stars
    star
    138
  • Rank 254,891 (Top 6 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Scala Test-State.

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.
    Use it conjunction with ScalaTest, Specs2, ฮผTest, etc.

  2. This is not a property testing library.
    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

  • Unit-test a webapp with Scala.JS.
  • Integration testing.
  • UAT automation.
  • Random-test (fuzz-test) like Android's monkeyrunner or ScalaCheck's Command API.
  • Data migration.

Features

  • Compiled for Scala & Scala.JS.
  • Can run synchronously, asynchronously (Future) or in your own context-type (eg IO). Is stack-safe.
  • Everything is immutable and composable.
  • Everything can be transformed into (reused in) different contexts.
  • Combines property and imperative testing.
  • Actions and assertions can be non-deterministic and/or dependent on runtime state.
  • Transparent and informative about test execution.
  • Includes an abstract DomZipper which greatly simplifies the task of HTML/SVG observation.
  • Comes with various DomZipper implementations and backends.
  • Lots of platform-specific utilities for web testing.
  • Configurable error handling. Be impure and throw exceptions or be pure and use a custom ADT to precisely maintain all forms of failure and error in your domain; it's up to you.
  • Extension modules for various 3rd-party libraries. (Cats, more.)

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.
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

Module Description JVM JS
core The core module. JVM JS
dom-zipper Standalone utility for observing web DOM with precision with conciseness.
This is the base API; concrete implementations below.
JVM JS
dom-zipper-jsoup DOM zipper built on Jsoup. JVM
dom-zipper-selenium DOM zipper built on Selenium.
Also comes with a fast version with uses Jsoup for nearly all operations which is 5-50x faster.
See doc/SELENIUM.md.
JVM
dom-zipper-sizzle DOM zipper built on Sizzle. JS
ext-cats Extensions for Cats. JVM JS
ext-nyaya Extensions for Nyaya. JVM JS
ext-scalajs-react Extensions for scalajs-react. JS
ext-selenium Extensions for Selenium. JVM

Examples

  • Scala.Js + React - Demonstrates DomZipper, invariants, actions, basics.
  • Selenium - Demonstrates Selenium testing of external web content, using retry scheduling (instead of Thread.sleep), parallelism and concurrency.
  • [TODO] DB triggers. - real external state, ref.
  • [TODO] Mutable sample. - fuzz, invariants.

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.

More Repositories

1

scalajs-react

Facebook's React on Scala.JS
Scala
1,627
star
2

svg-android

Fork of svg-android +SVN history +Maven +more
Java
566
star
3

scalacss

Super type-safe CSS for Scala and Scala.JS.
Scala
334
star
4

scala-graal

Make usage of Graal features easy and safe from Scala. Also features Scala-based React SSR.
Scala
194
star
5

nyaya

Random Data Generation and/or Property Testing in Scala & Scala.JS.
Scala
185
star
6

clear-config

Scala FP configuration library with a focus on runtime clarity
Scala
139
star
7

scalajs-benchmark

Benchmarks: write in Scala or JS, run in your browser. Live demo:
Scala
72
star
8

univeq

Safer universal equivalence (==) for Scala.
Scala
60
star
9

learning

Scala
47
star
10

setup-everything-scala

GitHub Action to prepare the environment for Scala & Scala.JS dev and testing
Scala
40
star
11

mr.boilerplate

Online app to generate Scala boilerplate
Scala
33
star
12

microlibs-scala

Scala
26
star
13

tla2json

Convert TLA+ output (and values) into JSON
Scala
22
star
14

webtamp

Asset bundler. Companion to bundlers like Webpack.
TypeScript
20
star
15

webapp-util

Scala Webapp Utilities
Scala
17
star
16

scala-restructure

Scala
9
star
17

misc

4
star
18

archlinux-packages

Shell
2
star
19

setup-scalajs

GitHub Action to prepare the environment for Scala.JS dev and testing
JavaScript
2
star
20

rubyprof-test

Ruby
1
star
21

setup-scala-util

GitHub Action to add Scala utilities to the PATH
Scala
1
star
22

ruby-corvid

Ruby
1
star
23

autotag2

Years-old app to tag MP3s.
Ruby
1
star
24

text_to_diagram

Generate software diagrams (ERDs, DFDs, etc) using text files, rather than spending hours combating visual tools.
Ruby
1
star
25

astacus

Ruby
1
star
26

android-test-utils

Java
1
star
27

ruby-golly-utils

Ruby
1
star