Documentation

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.

run

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

Run TestCase test

Syntax

result = run(testCase)
result = run(testCase,testMethod)

Description

result = run(testCase) uses testCase as a prototype to run a TestSuite array created from all test methods in the class defining testCase. This suite is run using a TestRunner object configured for text output.

result = run(testCase,testMethod) uses testCase as a prototype to run a TestSuite array created from testMethod. This test is run using a TestRunner object configured for text output.

This is a convenience method to allow interactive experimentation of TestCase classes in MATLAB®, yet running the tests contained in them using a supported TestRunner object.

Input Arguments

testCase

matlab.unittest.TestCase instance

testMethod

Name of desired test method, specified as one of the following:

  • character vector

  • meta.method instance

The method must correspond to a valid Test method of the testCase instance.

Output Arguments

result

A matlab.unittest.TestResult object containing the result of the test run.

Examples

expand all

Add the FigurePropertiesTest.m test case file to a folder on your MATLAB path.

classdef FigurePropertiesTest < matlab.unittest.TestCase
 
    properties
        TestFigure
    end
 
    methods(TestMethodSetup)
        function createFigure(testCase)
            % comment
            testCase.TestFigure = figure;
        end
    end
 
    methods(TestMethodTeardown)
        function closeFigure(testCase)
            close(testCase.TestFigure)
        end
    end
 
    methods(Test)
 
        function defaultCurrentPoint(testCase)
 
            cp = testCase.TestFigure.CurrentPoint;
            testCase.verifyEqual(cp, [0 0], ...
                'Default current point is incorrect')
        end
 
        function defaultCurrentObject(testCase)
            import matlab.unittest.constraints.IsEmpty
 
            co = testCase.TestFigure.CurrentObject;
            testCase.verifyThat(co, IsEmpty, ...
                'Default current object should be empty')
        end
 
    end
 
end

Create a testcase object.

tc = FigurePropertiesTest;

Run the tests.

tc.run;
Running FigurePropertiesTest
..
Done FigurePropertiesTest
__________

All tests passed.

Was this topic helpful?