Quantcast

Documentation Center

  • Trial Software
  • Product Updates

runtests

Run set of tests

Syntax

  • results = runtests(tests) example
  • results = runtests(tests,Name,Value) example

Description

example

results = runtests(tests) runs a set of tests, and returns the results as a TestResult object.

example

results = runtests(tests,Name,Value) runs a set of tests with additional options specified by one or more Name,Value pair arguments.

Examples

expand all

Run Tests Using File Name

Create the test file shown below, and save it as runtestsExampleTest.m on your MATLAB path.

function tests = runtestsExampleTest
tests = functiontests(localfunctions);

function testFunctionOne(testCase)

Run the tests.

results = runtests('runtestsExampleTest.m');
Running runtestsExampleTest
.
Done runtestsExampleTest
__________

Run Tests in Subdirectory

If it doesn't already exist, create the test file, runtestsExampleTest.m, in the example above.

Create a subdirectory, tmpTest, and, in that directory, create the following runtestsExampleSubFolderTest.m file.

function tests = runtestsExampleSubFolderTest
tests = functiontests(localfunctions);

function testFunctionTwo(testCase)

Run the tests from the directory above tmpTest by setting 'Recursively' to true.

results = runtests(pwd,'Recursively',true);
Running runtestsExampleTest
.
Done runtestsExampleTest
__________

Running runtestsExampleSubFolderTest
.
Done runtestsExampleSubFolderTest
__________

runtests ran the tests in both the current directory and the subdirectory.

If you do not specify the 'Recursively' property for the runtests function, it does not run the test in the subdirectory.

results = runtests(pwd);
Running runtestsExampleTest
.
Done runtestsExampleTest
__________

Run Select Parameterized Tests

In your working folder, create testZeros.m. This class contains four test methods.

classdef testZeros < matlab.unittest.TestCase
    properties (TestParameter)
        type = {'single','double','uint16'};
        outSize = struct('s2d',[3 3], 's3d',[2 5 4]);
    end
    
    methods (Test)
        function testClass(testCase, type, outSize)
            testCase.verifyClass(zeros(outSize,type), type);
        end
        
        function testSize(testCase, outSize)
            testCase.verifySize(zeros(outSize), outSize);
        end
        
        function testDefaultClass(testCase)
            testCase.verifyClass(zeros, 'double');
        end
        function testDefaultSize(testCase)
            testCase.verifySize(zeros, [1 1]);
        end
        
        function testDefaultValue(testCase)
            testCase.verifyEqual(zeros,0);
        end
    end
end

The full test suite has 11 test elements: 6 from the testClass method, 2 from the testSize method, and 1 each from the testDefaultClass, testDefaultSize, and testDefaultValue methods.

At the command prompt, run the test elements that use the outSize parameter property.

runtests('testZeros','ParameterProperty','outSize')
Running testZeros
........
Done testZeros
__________


ans = 

  1x8 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration

Totals:
   8 Passed, 0 Failed, 0 Incomplete.
   0.013499 seconds testing time.

runtests executed eight tests that use the outSize parameter property: six from the testClass method and two from the testSize method.

At the command prompt, run the test elements that use the singe parameter name.

runtests('testZeros','ParameterName','single')
Running testZeros
..
Done testZeros
__________


c = 

  1x2 TestResult array with properties:

    Name
    Passed
    Failed
    Incomplete
    Duration

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

runtests executed the two tests from the testClass method that use the outSize parameter name.

Input Arguments

expand all

tests — Array of testsstring | cell array of strings

Suite of tests specified as a string or cell array of strings. Each string in the cell array can contain the name of a test class, a test file, a package that containing your test classes, or a folder containing your test files.

Example: 'mypackage.MyTestClass'

Example: 'ATestFile.m'

Example: pwd

Example: {'mypackage.MyTestClass','ATestFile.m',pwd,'mypackage.subpackage'}

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example:

'Recursively' — Indicator to run tests in subfolders and subpackagesfalse (default) | true | 0 | 1

Indicator to run tests in subfolders and subpackages, specified as false or true (0 or 1). By default runtests runs tests in the specified folder or package and not in their subfolders or subpackages.

Data Types: logical

'Name' — Name of suite elementstring

String indicating the name of the suite element. For the testing framework to run a test, the Name property of the test element must match the specified name. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

'ParameterProperty' — Name of parameterization propertystring

String indicating the name of a property that defines a parameter used by the test suite element. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

'ParameterName' — Name of parameterstring

String indicating the name of a parameter used by the test suite element. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

'BaseFolder' — Name of base folderstring

String indicating the name of the folder that contains the file defining the test class or function. For the testing framework to run a test, the test element must be contained in the specified base folder. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character. For test classes defined in packages, the base folder is the parent of the top-level package folder.

See Also

| | |

Was this topic helpful?