matlab.unittest.TestCase.run - Run tests corresponding to test case - MATLAB (original) (raw)

Main Content

Class: matlab.unittest.TestCase
Namespace: matlab.unittest

Run tests corresponding to test case

Syntax

Description

result = run([testCase](#mw%5F1a05298d-be48-4523-b0c0-04f9959aa205)) runs all theTest methods of the class defining testCase and returns the result of the test run as a matlab.unittest.TestResult array, where each TestResult object corresponds to a Test method.

The run method is a convenience method for interactive experimentation with TestCase subclasses. It runs the tests by using a TestRunner instance that is configured for text output. The text output includes test run progress as well as diagnostics in the event of test failures.

example

result = run([testCase](#mw%5F1a05298d-be48-4523-b0c0-04f9959aa205),[method](#mw%5Fed718b5a-15a0-469c-b254-6ff4ea586e93)) runs the specified Test method of testCase.

example

Input Arguments

expand all

Test case, specified as a matlab.unittest.TestCase object.

Identifier of the Test method of testCase to run, specified as a string scalar, character vector, ormatlab.metadata.Method instance.

Examples

expand all

Test the properties of a figure by creating and running a test class.

In a file named FigurePropertiesTest.m in your current folder, create the FigurePropertiesTest test class by:

classdef FigurePropertiesTest < matlab.unittest.TestCase properties TestFigure end

methods (TestMethodSetup)
    function createFigure(testCase)
        testCase.TestFigure = figure;
        testCase.addTeardown(@close,testCase.TestFigure)
    end
end

methods (Test)
    function defaultCurrentPoint(testCase)
        cp = testCase.TestFigure.CurrentPoint;
        testCase.verifyEqual(cp,[0 0], ...
            "Default current point must be [0 0].")
    end

    function defaultCurrentObject(testCase)
        import matlab.unittest.constraints.IsEmpty
        co = testCase.TestFigure.CurrentObject;
        testCase.verifyThat(co,IsEmpty, ...
            "Default current object must be empty.")
    end
end

end

To run the tests interactively, create a test case from the test class. You also can use the forInteractiveUse static method to create a test case.

testCase = FigurePropertiesTest;

Run the tests corresponding to the test case. Both of the tests pass.

Running FigurePropertiesTest

. Done FigurePropertiesTest


result1 = 1×2 TestResult array with properties:

Name
Passed
Failed
Incomplete
Duration
Details

Totals: 2 Passed, 0 Failed, 0 Incomplete. 0.10772 seconds testing time.

Now, run the defaultCurrentPoint Test method.

result2 = run(testCase,"defaultCurrentPoint")

Running FigurePropertiesTest

. Done FigurePropertiesTest


result2 = TestResult with properties:

      Name: 'FigurePropertiesTest/defaultCurrentPoint'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 0.0553
   Details: [1×1 struct]

Totals: 1 Passed, 0 Failed, 0 Incomplete. 0.055328 seconds testing time.

Version History

Introduced in R2013a