Action performed when task runs
matlab.buildtool.TaskAction class defines a function that executes when
a task runs.
When you specify the actions of a task, you can use function handles instead of
TaskAction objects. MATLAB® automatically converts function handles to
Name — Name of action
Name of the action, returned as a string scalar. You can specify the value of this
property during creation of the action as a string scalar or character vector. If you do
not specify a value, the build tool sets the property to the string representation of
Specify Task Actions
Specify the actions to perform when a task runs.
In a file named
runMyTests.m in your current folder, create a function that runs the tests in the current folder and its subfolders, generates an HTML test report from the test results, and asserts that the tests run without failure.
function runMyTests(~) results = runtests(IncludeSubfolders=true,OutputDetail="terse"); generateHTMLReport(results,"artifacts") assertSuccess(results); end
Import the classes used in this example.
import matlab.buildtool.Task import matlab.buildtool.TaskAction
Create a plan with no tasks.
plan = buildplan;
Add a task to the plan that executes the
plan("test") = Task(Actions=@runMyTests);
Add another action to the task to open the generated test report.
plan("test").Actions(end+1) = TaskAction( ... @(~)open(fullfile("artifacts","index.html")),Name="Presenting");
Display the names of the task actions. Because you did not specify a name for the first action, the build tool displays the string representation of the function handle.
Now, run the task. The build runner performs the actions of the task in the order specified. In this example, all the tests pass and the report opens.
result = run(plan,"test");
** Starting test ... Generating test report. Please wait. Preparing content for the test report. Adding content to the test report. Writing test report to file. Test report has been saved to: C:\work\artifacts\index.html ** Finished test
Introduced in R2022b