matlab.buildtool.tasks.TestTask Class
Namespace: matlab.buildtool.tasks
Superclasses: matlab.buildtool.Task
Description
The matlab.buildtool.tasks.TestTask class provides a task for running a suite of tests using
the MATLAB® unit testing framework.
To improve build performance, a TestTask instance supports incremental
builds as well as running only the tests impacted by changes:
If the task is up to date, then the build tool skips the task. For details on how the build tool handles the task in incremental builds, see Up-To-Date Check.
If you have a MATLAB Test™ license, you can configure the task to run only the tests impacted by changes since the last successful task run. For more information, see Run Impacted Tests Using MATLAB Build Tool (MATLAB Test). (since R2025a)
Creation
Description
task = matlab.buildtool.tasks.TestTask creates a
task for running the tests in the current folder and its subfolders. The task fails if any
of the tests fail.
task = matlab.buildtool.tasks.TestTask(
creates a task that runs the tests in the specified files and folders, including their
subfolders.tests)
task = matlab.buildtool.tasks.TestTask(___,Name=Value)
sets writable properties using
one or more name-value arguments in addition to any of the input argument combinations in
previous syntaxes. You can also set the Description and
Dependencies properties, which the class inherits from the Task class,
using name-value arguments. For example, task =
matlab.buildtool.tasks.TestTask(TestResults="results.xml") creates a task that
produces test results in JUnit-style XML format.
Input Arguments
Properties
Methods
Examples
More About
Tips
A
TestTaskinstance respects the build output verbosity level specified at run time using the-verbosityoption of thebuildtoolcommand. The run-time verbosity level takes precedence over any values specified in theOutputDetailandLoggingLevelproperties. (since R2024b)To select tests by tag, use the
TagorSelectorproperty. For example, using theTagproperty, create a task that runs the tests with the"Feature1"tag.task = matlab.buildtool.tasks.TestTask(Tag="Feature1");Alternatively, create a task that runs the same tests by using the
Selectorproperty. (since R2025a)task = matlab.buildtool.tasks.TestTask( ... Selector=matlab.unittest.selectors.HasTag("Feature1"));
If you specify tags by using both the
TagandSelectorproperties, then the task runs only the tests that have all the specified tags. For example, this code creates a task that runs the tests with both the"Feature1"and"Feature2"tags.task = matlab.buildtool.tasks.TestTask( ... Tag="Feature1",Selector=matlab.unittest.selectors.HasTag("Feature2"));
You cannot overwrite or remove the action of a built-in task, but you can specify additional task actions. For example, append an action to the
Actionsproperty of a built-in task.plan("myTask").Actions(end+1) = @myAction;If you use MATLAB Test Manager to manage your tests (requires MATLAB Test), you can generate a code snippet that includes a
TestTaskinstance configured with the test and coverage settings from the test manager. For more information, see Configure Test Settings for Build Tool by Using MATLAB Test Manager (MATLAB Test). (since R2025a)