getSharedTestFixtures

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

Provide access to shared test fixtures

Syntax

fixtures = getSharedTestFixtures(testCase)
fixtures = getSharedTestFixtures(testCase,fixtureClassName)

Description

fixtures = getSharedTestFixtures(testCase) provides access to the array of all shared test fixtures for testCase. getSharedTestFixtures returns an array of fixture objects, fixtures. Specify shared fixtures are using the SharedTestFixtures attribute for the testCase class.

fixtures = getSharedTestFixtures(testCase,fixtureClassName) returns only the shared fixtures that have the class name fixtureClassName.

Input Arguments

testCase

matlab.unittest.TestCase instance

fixtureClassName

Name of test fixture class, specified as a string

Examples

expand all

Obtain Array of All Shared Fixtures

Create the following class, myTest, on your MATLAB® path. Two shared fixtures are used within the test method. This example assumes that the subfolder helperFiles exists in your working folder. Create the subfolder helperFiles in your working folder if it does not exist.

classdef (SharedTestFixtures={...
matlab.unittest.fixtures.PathFixture('helperFiles'),...
        matlab.unittest.fixtures.TemporaryFolderFixture}) ...
        myTest < matlab.unittest.TestCase
    methods(Test)
        function accessFixtures(testCase)
            myFixtures = testCase.getSharedTestFixtures
        end
    end
end

At the command prompt, run the test.

run(myTest);
Setting up PathFixture.
Description: Adds 'H:\Documents\doc_examples\helperFiles' to the path.
__________

Setting up TemporaryFolderFixture.
Description: Creates a temporary folder.
__________

Running myTest

myFixtures = 

  1x2 heterogeneous Fixture (PathFixture, TemporaryFolderFixture) array with no properties.

.
Done myTest
__________

Tearing down TemporaryFolderFixture.
Description: Deletes the temporary folder and all its contents.
__________

Tearing down PathFixture.
Description: Restores the path to its previous state.
__________

Access Shared Fixtures of Particular Class

Create the class, mySecondTest, on your MATLAB path.

classdef (SharedTestFixtures={...
        matlab.unittest.fixtures.TemporaryFolderFixture})...
        mySecondTest < matlab.unittest.TestCase
    methods(Test)
        function accessTemporaryFolderFixture(testCase)
            tempFolderFixture = testCase.getSharedTestFixtures...
                ('matlab.unittest.fixtures.TemporaryFolderFixture');
            temporaryFolder = tempFolderFixture.Folder
        end
    end
end

At the command prompt, run the test. The name of the temporary folder varies.

run(mySecondTest);
Setting up TemporaryFolderFixture.
Description: Creates a temporary folder.
__________

Running mySecondTest

temporaryFolder =

C:\Temp\tpb92c9c67_02fa_4714_bfb0_b2127df0f31d

.
Done mySecondTest
__________

Tearing down TemporaryFolderFixture.
Description: Deletes the temporary folder and all its contents.
__________
Was this topic helpful?