Main Content

functiontests

Create array of tests from handles to local functions

Description

tests = functiontests(f) creates an array of tests, tests, from a cell array of handles to local functions, f. To apply defined setup and teardown functions, include their function handles in f.

Local test functions must include ‘test’ at the beginning or end of the function name. functiontests must be called from within a test file.

example

Examples

collapse all

Create the file exampleTest.m in your MATLAB® path. In the main function, create a test array. Use local functions to define setup, teardown, and two function tests. Your file should look like this.

function tests = exampleTest
tests = functiontests(localfunctions);

function setup(testCase)
function teardown(testCase)
function exampleOneTest(testCase)
function testExampleTwo(testCase)

From the command line, call the exampleTest function.

tests = exampleTest
tests = 

  1x2 Test array with properties:

    Name
    ProcedureName
    TestClass
    BaseFolder
    Parameterization
    SharedTestFixtures
    Tags

Tests Include:
    0 Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.

Access the test suite to verify the names of the two function tests.

tests.Name
ans =

    'exampleTest/exampleOneTest'


ans =

    'exampleTest/testExampleTwo'

Input Arguments

collapse all

Handles to local test functions, specified as a cell array. Use f=localfunctions in your working file to automatically generate a cell array of function handles for that file. If you want explicit test enumeration, construct f by listing individual functions. f must include any setup or teardown functions necessary for your test.

Example: f = localfunctions;

Example: f = {@setup,@exampleOneTest,@teardown};

Version History

Introduced in R2013b