This is a study note of uTest: a simple, intuitive testing library for Scala. It features a uniform syntax for writing and running tests using a uniform assertion syntax.

Essential Features

uTest only supports the essential testing tasks:

  • writing test suite and tests
  • sharing initialization between various tests
  • asserting results with expected
  • selecting which tests to run

Write and Run Tests

Use TestSuite to define a suite and group tests in Tests. Use test("name") method inside Tests to write each test that can be nested.

Shared code are defined in a block. Global variables are defined outside Tests.

Use TestRunner.runAsync(tests) to run async tests and return a Future[T], or use TestRunner.run(tests) to run and wait.

Smart Asserts

uTest uses a macro-powered assert method that takes one or more bollean expressions.

Use a ==> b as a shorthand for assert(a == b).

Use intercept[ErrorType] to verify that a block raises an exception.

eventually(tests: Boolean*) at least once true in a certain period of time. continually(tests: boolean*) alwasy true in a period. RetryMax and TretryInterval customize the check.

assertMatch checks pattern matching.

compileError asserts that a fragment of code fails to compile.

Test Uitilities

The implicit value test.framework.TestPath is passed to each test. It has a sequence of strings that matches the current test path.

Use retry(number) to retry tests. Use TestSuite.Retries for suite retries.

Use setup() and teardown() to do pre-test and after-tests global tasks in utest.runner.Framework.

Use utestBeforeEach and utestAfterEach for pre and after work for each test in TestSuite. Use utestBeforeAll and utestAfterAll for the suite.

Use TestRunner.run(tests) to run uTest standalone.