matlab.unittest.TestSuite.fromProject

Class: matlab.unittest.TestSuite
Package: matlab.unittest

Create test suite array from tests in project

Syntax

suite = matlab.unittest.TestSuite.fromProject(project)
suite = matlab.unittest.TestSuite.fromProject(project,selector)
suite = matlab.unittest.TestSuite.fromProject(project,Name,Value)

Description

suite = matlab.unittest.TestSuite.fromProject(project) creates a TestSuite array from all test files contained in the specified project that are labeled with the Test classification. The project input is either a loaded matlab.project.Project object or the root folder of a project. This method is not recursive. It includes only those tests in the project specified. To include tests from referenced projects, set 'IncludingReferencedProjects' to true. For more information on projects, see Projects.

suite = matlab.unittest.TestSuite.fromProject(project,selector) creates a TestSuite array from all test files contained in the specified project that are labeled with the Test classification and that satisfy the selector. For more information on selectors, see matlab.unittest.selectors Package.

suite = matlab.unittest.TestSuite.fromProject(project,Name,Value) creates a TestSuite array from all test files contained in the specified project that are labeled with the Test classification and that satisfy the conditions specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Project containing test files, specified as the path to the project root folder or an open Project object. A test file is a file that is classified as test by adding the Test label in the project.

Example: 'C:\MyProjects\ThisProject'

Data Types: char | string

Filter for TestSuite array elements, specified as an instance of a selector class from the matlab.unittest.selectors Package.

Example: matlab.unittest.selectors.HasBaseFolder(fullfile(pwd,'MyTests','Feature1'))

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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Folder containing tests to include in TestSuite array, specified as an absolute or relative path. Use this argument to filter TestSuite array elements to those tests in the specified folder. For a test element to be included in the suite, 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.

Data Types: char | string

External parameters to use with test, specified as an instance of a class in the matlab.unittest.parameters Package. Parameter instances provide external data for use in parameterized tests. The framework uses these external parameters in place of the corresponding parameters that are defined within a parameterized test. For more information, see Use External Parameters in Parameterized Test.

Indicate whether to include tests from referenced projects in the TestSuite, specified as logical true or false. By default, fromProject includes test files only from the project specified in the input. Passing a value of true for IncludingReferencedProjects results in a TestSuite array that includes the tests from the project specified in the input and tests from projects referenced from the parent project. For more information on referenced projects, see Componentize Large Projects.

Example: suite = matlab.unittest.TestSuite.fromProject(project,'IncludingReferencedProjects',true);

Data Types: logical

Name of test element in TestSuite array, specified as a character vector or string scalar. Use this argument to filter TestSuite array elements to those tests that have the specified name. To include a test element in the suite, the Name property of the test element must match the specified value for Name. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

Example: suite = matlab.unittest.TestSuite.fromProject(project,'Name','testZeros/testSize');

Data Types: char | string

Name of a parameter used by the test suite element, specified as a character vector or a string scalar. Use this argument to filter TestSuite array elements to those tests that use the specified parameter. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

Data Types: char | string

Name of property that defines a parameter used by TestSuite array element, specified as character vector or a string scalar. Use this argument to filter TestSuite array elements to those tests that have the named property. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

Data Types: char | string

Name of test procedure, specified as a character vector or a string scalar. Use this argument to filter TestSuite array elements to those that have the named test procedure. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

Data Types: char | string

Name of the test class superclass, specified as a character vector or string scalar. Use this argument to filter TestSuite array elements to those tests that derive from the specified superclass.

Data Types: char | string

Name of the tag applied to TestSuite array element, specified as a character array or string scalar. Use this argument to filter TestSuite array elements to those tests with the specified tag. Use the wildcard character, *, to match any number of characters. Use the question mark character, ?, to match to exactly one character.

Data Types: char | string

Output Arguments

expand all

Set of tests, returned as a matlab.unittest.Test array

Attributes

Statictrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Build a test suite from project files that are labeled as Test files. This example assumes that a project folder at C:/projects/project1 contains test files that are labeled with the Test classification. Use the matlab.unittest.TestSuite.fromProject static method to create a test suite using those tests.

Open project1 and pass the matlab.project.Project object to fromProject. Run the test suite and capture the results.

import matlab.unittest.TestSuite
project = openProject('C:/projects/project1/');
suite = TestSuite.fromProject(project);
result = run(suite)

Build a test suite from project files that are labeled as Test files in the project and all referenced projects.

import matlab.unittest.TestSuite
project = openProject('C:/projects/project1/');
suite = TestSuite.fromProject(project,'IncludingReferencedProjects',true);
result = run(suite)

Introduced in R2019a