addTeardown

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

Dynamically add teardown routine

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 teardown code is executed in the reverse order to which it is added. This is known as LIFO (or Last-In-First-Out).

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

Call addTeardown in a TestMethodSetup Method

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