ecl-logo Documentation

Test

Test[description,expression,expectedValue]test

returns an executable test which will evaluate expression and determine if it matches expectedValue.

Details

  • The following Options MUST be specified as RuleDelayed: Messages,SetUp,TearDown,Variables,Stubs.
  • The function definitions specified in the Stubs Options list are only applicable during the execution of the test. During the execution of the test, all previously specified definitions for the stubbed out symbols will be ignored and after the test is executed the stubbed out definitions will be forgotten.
  • The 'Stubs' Options differentiates between Set & SetDelayed calls. A SetDelayed call will clear all definitions for the symbol before applying the Stub definition, whereas a Set call will prepend the definition to the existing DownValues for the symbol.
  • The 'Set' Stubs (which prepend DownValues) works by copying all the DownValues/OwnValues/UpValues/Options/Attributes for a symbol during a test and as a result will not work with built in Mathematica symbols whose DownValues, OwnValues, etc., are not exposed. However, The SetDelayed method for clearing the symbol will always work.
  • Input
    Output
    General Options
    Attributes
  • HoldRest

Examples

Basic Examples  (1)

Define a test that asserts 2+2=4:

Options  (13)

Category  (1)

Categorize a Test:

EquivalenceFunction  (1)

Define a test that uses Equal for result comparison instead of MatchQ:

FatalFailure  (1)

Flag a Test as a "Fatal Failure", causing the test run to be stopped on failure of this test:

Messages  (1)

Define a test that expects a Message to be thrown:

SetUp  (1)

Specify expressions to be run before the Test:

Stubs  (2)

Re-define the entire behaviour of a symbol within the context of a Test using a SetDelayed Stub:

Prepend a DownValue to a symbol within the context of a Test using a Set Stub:

SubCategory  (1)

Sub-Categorize a Test:

TearDown  (1)

Specify expressions to be run after the Test:

TimeConstraint  (1)

Define a test expects execution of the test to be < 2 seconds:

Variables  (2)

Specify variables to share between test and expected value expressions:

Specify variables to share between SetUp, TearDown, test, and expected value expressions:

Warning  (1)

Flag test as being a Warning and should not cause a failure in RunUnitTest:

Attributes  (1)

HoldRest  (1)

Holds all inputs except the first: