Test Expressions


There are several possible forms for test expressions, as well as some options that will be useful to you as you create tests.

Basic Test Usage

The basic use has three arguments: the evaluation under test, the expected output, and the test identifier.

Test Expressions

Messages

If messages are expected, they should be a part of the test. List expected message names in the third argument; the identifier becomes the fourth argument.

Testing Messages

Options

By default the result is compared to the expected result using SameQ; i.e., they must be the exact same expression for the test to pass. Use the option EquivalenceFunction to change this, depending on the type of testing you require.

Message names are also compared using SameQ; this can be changed with the option MessageEquivalenceFunction.

Setup and Teardown

If you require large amounts of logic for a test, this should really be outside of a test expression. Test files execute sequentially, so it is perfectly safe to have required logic evaluate separately.

Tips

You should always write tests in such a way so that when there is a failure, you describe that failure in some way. Try to avoid Boolean expected output, as this is not very descriptive when failures occur.