matlabtest.coder.MEXReplacementTestSuite.fromFolder
Class: matlabtest.coder.MEXReplacementTestSuite
Namespace: matlabtest.coder
Syntax
Description
specifies options using one or more name-value arguments in addition to the input argument
combinations in previous syntaxes.suite
= matlabtest.coder.MEXReplacementTestSuite.fromFolder(___,Name=Value
)
Input Arguments
Test folder to create the test suite from, specified as a string scalar or character vector. If you specify a relative path, the path must be relative to the current folder. Otherwise, you must specify a full path.
Example: pwd
Example: "myFolder"
Example: "C:\work\myFolder"
MEX function to call in tests, specified as a string scalar, character vector, string array, cell array of character vectors, or cell array of string scalars. Specify the relative or full path to the MEX function. You do not need to include the file extension.
Example: "myMexFcn"
Example: "myMexFcn.mexw64"
Example: ["myMexFcn1","myMexFcn2"]
Example: {'myMexFcn1','myMexFcn2'}
Selector, specified as a matlab.unittest.selectors.Selector
object.
Example: matlab.unittest.selectors.HasTag("SystemTests")
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: suite =
matlabtest.coder.MEXReplacemetTestSuite.fromFolder("tests","myMexFcn.mexw64",ProcedureName="myTest")
Name of the base folder that contains the tests, specified as a string array, character
vector, or cell array of character vectors. This argument filters the test suite. For
the testing framework to include a test in the filtered suite, the
Test
element must be contained in one of the base folders
specified by BaseFolder
. If none
of the Test
elements are in the base folder, the function returns an
empty test suite. 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 namespaces, the base folder is the parent of the top-level namespace folder.
Example: BaseFolder="tests"
Names of files and folders to find dependent tests for, specified as a string vector, character vector, or cell vector of character vectors. This argument filters the test suite by including only the tests that depend on the specified files and folders. If none of the tests depend on the files and folders, the function returns as empty test suite.
The specified value must represent at least one existing file. If you specify a folder, the framework extracts the paths to the files within the folder.
You must have a MATLAB
Test™ license to use DependsOn
. For more information about
selecting tests by source code dependency, see matlabtest.selectors.DependsOn
.
Example: DependsOn=["myFile.m" "myFolder"]
Example: DependsOn=["folderA" "C:\work\folderB"]
External parameters to use in the tests, specified as an array of matlab.unittest.parameters.Parameter
objects. Use this argument to specify
external parameters outside of the parameterized test.. For more information, see Use External Parameters in Parameterized Test.
Option to include the tests in the subfolders of folder
,
specified as a numeric or logical 0
(false
) or
1
(true
). By default, the method does not
include the tests in subfolders.
Action to take against the invalid test files in folder
,
specified as one of these values:
"warn"
— The method issues a warning for each invalid test file infolder
and creates a test suite from the valid files."error"
— The method throws an error if it finds an invalid test file infolder
.
An invalid test file is a test file from which the framework cannot generate a test
suite. Examples include a test file that contains syntax errors, a function-based test
file that is missing local functions, or a file with a Test
method
that is passed an undefined parameterization property.
Name of the test, specified as a string array, character vector, or cell array of character
vectors. This argument filters the test suite. For
the testing framework to include a test in the
filtered suite, the Name
property
of the Test
element must match
one of the names specified by
Name
. If
none of the
Test
elements have a matching
name, the function returns an empty test suite. Use
the wildcard character (*
) to
match any number
of characters. Use the question mark character
(?
) to match a single
character.
For a given test file, the name of a test uniquely identifies the smallest runnable portion of the test content. The test name includes the namespace name, filename (excluding the extension), procedure name, and information about parameterization.
Example: Name="myTestFile/myTestProcedure"
Name of a test class property that defines a parameter used by the test, specified as
a string array, character vector, or cell array of character vectors. This argument
filters the test suite. For the testing framework to include a test in the filtered
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 have a matching property name, the function returns
an empty test suite. Use the wildcard character (*
) to match
any number of characters. Use the question mark
character (?
) to match a single character.
Name of a parameter used by the test, 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. For example:
If the property value is a cell array, MATLAB generates parameter names from the elements of the cell array based on their values, types, and dimensions.
If the property value is a structure, MATLAB generates parameter names from the structure fields.
The ParameterName
argument filters the test suite. For the testing
framework to include a test in the filtered 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 have a matching parameter name, the function
returns an empty test suite. 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 the test suite. For the testing
framework to include a test in the filtered suite, the
ProcedureName
property of the
Test
element must match one of the procedure
names specified by ProcedureName
. If
none of the Test
elements have a matching procedure name, the function returns an empty test
suite. 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 name of a test procedure is the name of a Test
method that contains the test. In a function-based test, it is the name of a
local function that contains the test. In a script-based test, it is a name
generated from the test section title. Unlike the name of a test suite
element, the name of a test procedure does not include namespace names,
filenames, or information about parameterization.
Example: ProcedureName="myTestProcedure"
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 the test
suite. For the testing framework to include a test in the filtered 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 match a class, the function returns an empty test suite.
Example: Superclass="matlab.unittest.TestCase"
Name of a tag used by the test, specified as a string array, character vector, or cell array
of character vectors. This argument filters the test suite. For the testing
framework to include a test in the filtered 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 have a matching tag name, the
function returns an empty test suite. Use the wildcard character
(*
) to match
any number of characters. Use the
question mark character (?
) to match a single
character.
Example: Tag="SystemTests"
Output Arguments
MEX replacement test suite, returned as an array of matlab.unittest.Test
objects.
Examples
This example uses:
Create MEX replacement test suites by using the
matlabtest.coder.MEXReplacementTestSuite.fromFolder
method.
Open the ShortestPath
project and generate a MEX function from the
shortest_path
function with the required input types and
sizes.
openExample("matlabtest/ShortestPathExample") cfg = coder.config("mex"); mtxType = coder.typeof(ones(100,100),[],1); scalarDbl = coder.typeof(1); codegen shortest_path -args {mtxType,scalarDbl,scalarDbl} -config cfg
Code generation successful.
Import the matlabtest.coder.MEXReplacementTestSuite
and matlab.unittest.selectors.HasTag
classes.
import matlabtest.coder.MEXReplacementTestSuite import matlab.unittest.selectors.HasTag
Create a MEX replacement test suite from the tests in the tests
folder. Specify the MEX file to call in the test, shortest_path_mex
.
testFolder = "tests"; mexFcn = which("shortest_path_mex"); suite1 = MEXReplacementTestSuite.fromFolder(testFolder,mexFcn); disp({suite1.Name}')
{'graph_unit_tests/check_longest_path' } {'graph_unit_tests/check_unity_path' } {'graph_unit_tests/check_non_unique' } {'graph_unit_tests/check_no_path' } {'graph_unit_tests/check_start_end_same' } {'graph_unit_tests/check_invalid_idx_empty_adj' } {'graph_unit_tests/check_edgeless_graph' } {'graph_unit_tests/check_edgeless_start' } {'graph_unit_tests/check_edgeless_end' } {'graph_unit_tests/check_edgeless_graph_self_loop'} {'graph_unit_tests/check_invalid_start_1' } {'graph_unit_tests/check_invalid_start_2' } {'graph_unit_tests/check_invalid_end_1' } {'graph_unit_tests/check_invalid_end_2' } {'tDemoSmokeTest/demoShouldNotWarn' }
Create a test suite that includes only the tests that have the tag
InputTests
in the tests
folder.
selector = HasTag("InputTests"); suite2 = MEXReplacementTestSuite.fromFolder( ... testFolder,mexFcn,selector); disp({suite2.Name}')
{'graph_unit_tests/check_invalid_start_1'} {'graph_unit_tests/check_invalid_start_2'} {'graph_unit_tests/check_invalid_end_1' } {'graph_unit_tests/check_invalid_end_2' }
Create a test suite that includes only the tests whose name contains
edgeless
from the tests
folder.
suite3 = MEXReplacementTestSuite.fromFolder( ... testFolder,mexFcn,Name="*edgeless*"); disp({suite3.Name}')
{'graph_unit_tests/check_edgeless_graph' } {'graph_unit_tests/check_edgeless_start' } {'graph_unit_tests/check_edgeless_end' } {'graph_unit_tests/check_edgeless_graph_self_loop'}
Run the tests.
results = run([suite1 suite2 suite3]);
Setting up MEXReplacementFixture Done setting up MEXReplacementFixture: Replacing MATLAB function calls with the specified MEX functions __________ Running graph_unit_tests .......... .... Done graph_unit_tests __________
Alternatives
You can also use the coder.runTest
(MATLAB Coder) function to run existing tests that replace calls to
MATLAB functions with calls to MEX functions. However, the
matlabtest.coder.MEXReplacementTestSuite
class provides these
advantages over the coder.runTest
(MATLAB Coder) function:
You can run tests from multiple test files.
You can collect coverage for the generated C/C++ code.
You can generate test and coverage reports from the results.
You can run MEX replacement test suites on CI platforms.
You can run MEX replacement test suites and MATLAB test suites in the same run by executing a single command.
For more information, see Verify Generated C/C++ Code by Running Existing MATLAB Tests.
Version History
Introduced in R2025a
See Also
Classes
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)