This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Create array of tests from handles to local functions


tests = functiontests(f)



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.


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:


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

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

ans =


ans =


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};

Introduced in R2013b