addTeardown

Class: matlab.unittest.TestCase
Package: matlab.unittest

Dynamically add teardown routine to TestCase instance

Syntax

addTeardown(testCase,tearDownFcn)
addTeardown(testCase,tearDownFcn,arg1,...,argN)

Description

addTeardown(testCase,tearDownFcn) adds the tearDownFcn function handle that defines fixture teardown code to the testCase instance.

The function handle executes in the scope where it is registered. This scope can be a test class, a test method, or a shared fixture. The teardown code is executed in the reverse order to which it is added. This is a last-in, first-out (LIFO) execution order policy. To restore the correct pre-test state, the function handle is dynamically invoked with the conclusion of the scope.

addTeardown(testCase,tearDownFcn,arg1,...,argN) provides input arguments to the tearDownFcn.

Input Arguments

testCase

matlab.unittest.TestCase instance

tearDownFcn

Function, specified as a function handle, that defines the fixture teardown code

arg1,...,argN

Input arguments, 1 through N (if any), required by tearDownFcn, specified by any type. The argument type is specified by the function argument list.

Examples

expand all

classdef SomeTest < matlab.unittest.TestCase
 
    methods(TestMethodSetup)
        function createFixture(testCase)
            p = path;
            testCase.addTeardown(@path, p);
            addpath(fullfile(pwd,'testHelpers'));
        end
    end
end