Skip to content
This repository has been archived by the owner on Mar 16, 2020. It is now read-only.

Latest commit

 

History

History
54 lines (35 loc) · 3.54 KB

actions.md

File metadata and controls

54 lines (35 loc) · 3.54 KB
layout title
docs
Actions

Actions

Actions are created using functions contained in

src/main/scala/com/fortysevendeg/lambdatest/package.scala

Additional actions can be easily defined.

Simple Actions

Simple actions do not contain other actions.

  • assert. Tests a boolean predicate. See the Example demo.
  • assertEq. Tests that two values are equal. See the Example demo.
  • assertEx. Test that an exception is raised. See the Except demo
  • assertSC. Used to test a ScalaCheck property. See the ScalaCheck demo.
  • exec. Used to insert Scala code. See the Mutable demo.
  • assertPerf. Runs an expression multiple times and reports mean, max, and stdDev. Can assert a maximum mean and max. See the Timing demo.

Compound Actions

Compound actions contain other actions within themselves.

  • label. Introduced a labeled block of code. See the Example demo.
  • test. Defines a named test. See the Example demo.
  • changeOptions. Used to change options within its body. See the FailOnly test.
  • timer. Reports the execution time of its body. See the Timing demo.
  • assertTiming. Reports the execution time of its body. Fails if a max time is exceeded. See the Timing demo.
  • nest. Used to nest declarations in immutable tests. See the Immutable demo.

Assertion Nesting Rule

  • Assertions must be either directly or indirectly inside a test.

See Bad demo for what not to do.

Including Scala Code

Suppose we have a test that contains several assertions. We can add arbitrary code as follows.

  • Before all assertions. Put the code in the body of the test action. See the Mutable demo.
  • Between assertions (mutable). Add exec actions between assertions. See the Mutable demo.
  • Between assertions (immutable). Use nesting. See the Immutable demo.
  • After all assertions. The can be done using a user defined compound action called a wrapper. See the Wrap demo. Wrappers are used instead of the before and after features of other testing frameworks. Wrappers avoid the need to use mutable state and can easily capture exceptions