This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.unittest.plugins.QualifyingPlugin class

Package: matlab.unittest.plugins
Superclasses: matlab.unittest.plugins.TestRunnerPlugin

Interface for plugins that perform system-wide qualifications


Use qualifying plugins to produce test failures apart from your test content. Qualifications at the plugin level are useful because you can avoid repeating the same qualification in every test. You can decide to apply system-wide qualifications to the test suite periodically by simply adding the plugin to the test runner for a particular test session.

The QualifyingPlugin interface enables test runner plugin authors to implement plugins that perform system-wide qualifications on a test suite. You can perform verifications, assumptions, assertions, and fatal assertions in these inherited methods:

  • setupTestClass

  • teardownTestClass

  • setupTestMethod

  • teardownTestMethod

You can perform only assumptions, assertions, and fatal assertions in these inherited methods:

  • setupSharedTestFixture

  • teardownSharedTestFixture


assertUsingAssert that value satisfies given constraint
assumeUsingAssume that value satisfies given constraint
fatalAssertUsingFatally assert that value satisfies given constraint
verifyUsingVerify that value satisfies given constraint

Inherited Methods

createSharedTestFixtureExtend creation of shared test fixture instances
createTestClassInstanceExtend creation of class-level TestCase instances
createTestMethodInstanceExtend creation of method-level TestCase instances
reportFinalizedResultEnable reporting of finalized TestResults
runTestExtend running of single TestSuite element
runTestClassExtend running of TestSuite array from same class or function
runTestMethodExtend running of single Test method
runTestSuiteExtend running of TestSuite array
setupSharedTestFixtureExtend setting up shared test fixture
setupTestClassExtend setting up test class
setupTestMethodExtend setting up of test method
teardownSharedTestFixtureExtend tearing down shared test fixture
teardownTestClassExtend tearing down of test class
teardownTestMethodExtend tearing down of test method

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.


expand all

Create a plugin to ensure that test files leaves the MATLAB® path unchanged. If the path after running the test file is different from the starting path, the test fails.

Create a class, VerifyNoPathChangePlugin, that inherits from the matlab.unittest.plugins.QualifyingPlugin class.

classdef VerifyNoPathChangePlugin < matlab.unittest.plugins.QualifyingPlugin
    properties (Access=private)
    methods (Access=protected)
        function setupTestClass(plugin, pluginData)
            plugin.OriginalPath = path;
        function teardownTestClass(plugin, pluginData)
            import matlab.unittest.constraints.IsEqualTo;
            plugin.verifyUsing(pluginData.QualificationContext, ...
                path, IsEqualTo(plugin.OriginalPath), ...
                sprintf('%s modified the path.', pluginData.Name));

Create the following test class. The test modifies the path, but does not restore the original path.

classdef LeavesModifiedPath < matlab.unittest.TestCase
    methods (Test)
        function test1(~)

For purposes of this example, at the command prompt, remove the present working folder from the path.


Create a test suite, add the plugin to the test runner, and run the suite. The test fails because the path after the test is different from the starting path.

suite = matlab.unittest.TestSuite.fromClass(?LeavesModifiedPath);
runner = matlab.unittest.TestRunner.withTextOutput;
Running LeavesModifiedPath
Verification failed while setting up or tearing down LeavesModifiedPath.
As a result, all LeavesModifiedPath tests failed.

    Test Diagnostic:
    LeavesModifiedPath modified the path.

    Framework Diagnostic:
    IsEqualTo failed.
    --> StringComparator failed.
        --> The character arrays are not equal.
    Actual char:
        C:\work;C:\Program Files\MATLAB\R2015b\toolbox\matlab\...
   Expected char:
        C:\Program Files\MATLAB\R2015b\toolbox\matlab\...

    Stack Information:
    In C:\work\VerifyNoPathChangePlugin.m (VerifyNoPathChangePlugin.teardownTestClass) at 14

Done LeavesModifiedPath

Failure Summary:

     Name                      Failed  Incomplete  Reason(s)
     LeavesModifiedPath/test1    X                 Failed by verification.

Introduced in R2015b

Was this topic helpful?