Skip to main content

bdd

Behavior-driven testing library for running unit tests

Status

Experimental: Functionality may change for any reason, without semantic versioning guarantees

Availability

This module is preloaded. You can simply require it:

local bdd = require("bdd")

Functions

describe

Signals to the test runner that a new section should be started. You should only ever call this from within a test file.

getElapsedTime

Returns a human-readable string representation of the elapsed time for the current test run, which is the period between the last call to startTestRunner and now. If the tests have all been executed, the elapsed time is the total duration of the test run.

getErrorDetails

Returns a table containing error information about the last (or current) test run. Errors accumulate in-order; i.e., the table is an array.

ErrorDetails
FieldType
messagestring
specFilestring
stackTracestring

getHumanReadableTime

This utility method formats a duration, assumed to be given in nanoseconds, for human consumption. You cannot rely on the format being stable, just that it's easy to read (for an arbitrary definition of "easy"). It's intended to format the time for completed test runs.

getReport

Returns the contents of the internal report buffer. You can use this after the test run has finished in order to print a summary.

isBasicReportingMode

Returns whether the test runner is set to use the basic reporting mode.

isDetailedReportingMode

Returns whether the test runner is set to use the detailed reporting mode.

isMinimalReportingMode

Returns whether the test runner is set to use the minimal reporting mode.

it

Signals to the test runner that a new subsection should be started. You should only ever call this from within a test file.

report

Adds a given message to the internal report buffer, so that it will be included in the final report after all tests have run. Inserts newlines (\n) after each message to simulate print-like semantics. Converts non-string values according to the usual LuaJIT conventions.

reset

Resets the test runner's internal state to its default values. This will happen automatically whenever you start a new test runner.

setBasicReportMode

Enables the basic reporting mode (must be called before starting the test runner). Only one reporting mode can be active.

setDetailedReportMode

Enables the detailed reporting mode (must be called before starting the test runner). Only one reporting mode can be active.

setMinimalReportMode

Enables the minimal reporting mode (must be called before starting the test runner). Only one reporting mode can be active.

startTestRunner

Starts a new test runner for the given list of test files. It will merely execute the tests, without reporting results or error details1. After a test run has completed, any errors that occured during it can be queried via getErrorDetails, and reports via getReport.

1 The exact behavior depends on the reporting mode used. In some modes, the runner will fail loudly when encountering an error.

caution

Only one test runner can be started at a time. Manipulating its state from inside the tests may lead to undefined behavior.

Changelog

VersionWhat happened?
v0.0.1Initial release