Main Content

matlab.unittest.TestSuite.fromProject

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

Create test suite array from tests in project

Description

example

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.

example

suite = matlab.unittest.TestSuite.fromProject(___,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 arguments. Specify the name-value arguments after all of the arguments in any of the previous syntaxes.

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 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.

Name of the base folder that contains the file defining the test class, function, or script, specified as a string array, character vector, or cell array of character vectors. This argument filters TestSuite array elements. For the testing framework to include a test in the suite, the Test element must be contained in one of the base folders specified by BaseFolder. If none of the Test elements matches a base folder, an empty test suite is returned. Use the wildcard character * to match any number of characters. Use the question mark character ? to match a single character. For test files defined in packages, the base folder is the parent of the top-level package folder.

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 the suite element, specified as a string array, character vector, or cell array of character vectors. This argument filters TestSuite array elements. For the testing framework to include a test in the suite, the Name property of the Test element must match one of the names specified by Name. If none of the Test elements has a matching name, an empty test suite is returned. Use the wildcard character * to match any number of characters. Use the question mark character ? to match a single character.

Name of a test class property that defines a parameter used by the test suite element, specified as a string array, character vector, or cell array of character vectors. This argument filters TestSuite array elements. For the testing framework to include a test in the suite, the Parameterization property of the Test element must contain at least one of the property names specified by ParameterProperty. If none of the Test elements has a matching property name, an empty test suite is returned. Use the wildcard character * to match any number of characters. Use the question mark character ? to match to a single character.

Name of a parameter used by the test suite element, specified as a string array, character vector, or cell array of character vectors. MATLAB® generates parameter names based on the test class property that defines the parameters:

  • If the property value is a cell array of character vectors, MATLAB generates parameter names from the values in the cell array. Otherwise, MATLAB specifies parameter names as value1, value2, …, valueN.

  • If the property value is a structure, MATLAB generates parameter names from the structure fields.

The ParameterName argument filters TestSuite array elements. For the testing framework to include a test in the suite, the Parameterization property of the Test element must contain at least one of the parameter names specified by ParameterName. If none of the Test elements has a matching parameter name, an empty test suite is returned. Use the wildcard character * to match any number of characters. Use the question mark character ? to match a single character.

Name of the test procedure, specified as a string array, character vector, or cell array of character vectors. This argument filters TestSuite array elements. For the testing framework to include a test in the suite, the ProcedureName property of the Test element must match one of the procedure names specified by ProcedureName. If none of the Test elements has a matching procedure name, an empty test suite is returned. Use the wildcard character * to match any number of characters. Use the question mark character ? to match a single character.

In a class-based test, the ProcedureName is the name of the test method. In a function-based test, it is the name of the local function that contains the test. In a script-based test, it is a name generated from the test section title. Unlike Name, the name of the test procedure does not include any class or package name or information about parameterization.

Name of the class that the test class derives from, specified as a string array, character vector, or cell array of character vectors. This argument filters TestSuite array elements. For the testing framework to include a test in the suite, the TestClass property of the Test element must point to a test class that derives from one of the classes specified by Superclass. If none of the Test elements matches a class, an empty test suite is returned.

Name of a test tag used by the test suite element, specified as a string array, character vector, or cell array of character vectors. This argument filters TestSuite array elements. For the testing framework to include a test in the suite, the Tags property of the Test element must contain at least one of the tag names specified by Tag. If none of the Test elements has a matching tag name, an empty test suite is returned. Use the wildcard character * to match any number of characters. Use the question mark character ? to match a single character.

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)

Compatibility Considerations

expand all

Behavior changed in R2021b

Introduced in R2019a