Generate initial test code for script or function
Interactively create tests for your scripts and functions in the Editor or Live Editor. The test file created for a script or function contains a test class to exercise that script or function. You can use this file as a starting point for adding your own tests. For more information, see Create Tests for MATLAB Source Code.
Generate standalone code coverage report
Use the matlabtest.plugins.codecoverage.StandaloneReport class or the generateStandaloneReport method to generate a standalone code coverage report as
a single HTML file. You can generate this code coverage report for MATLAB® source code as well as C/C++ code in equivalence tests.
Generate deployable archive for MATLAB Production Server and test for equivalence with MATLAB source code
Author equivalence tests that use MATLAB Compiler SDK™ to build a deployable archive for MATLAB Production Server™ or other microservices. Execute the deployable archive and verify that the execution of the deployable archive and the MATLAB source code match. You can build a deployable archive outside of a test and verify the deployable archive by using an equivalence test. For more information, see Generate Deployed Code Artifacts and Test for Equivalence.
Specify any type of source file when selecting tests by source code dependency
When you create a selector using the matlabtest.selectors.DependsOn class, the selector supports source files of
any type. In previous releases, the selector supports
files only with a .m, .p, .mlx,
.mlapp, .mat, or .slx
extension.
Display MATLAB Test Manager test failure diagnostics in the MATLAB Command Window
Display the diagnostics in the MATLAB Command Window for failed tests that you run by using the MATLAB Test
Manager. In the MATLAB Test Manager, next to the Run button
, click the Expand icon
and select Enable logged
diagnostics.
View coverage summary in the MATLAB Test Manager
View a coverage summary for the tests in the current test suite in the MATLAB Test Manager. When you enable coverage, the MATLAB Test Manager displays the Statement button. The Statement button shows the statement coverage percentage for the current test suite. To view the coverage summary for other coverage metrics, point to the Statement button, or open the coverage report for the current test suite by clicking the button. For more information, see Interactively Collect Code Coverage.
Generate code coverage report in Cobertura XML format for generated C code in equivalence tests
Create a code coverage report in the Cobertura XML format for generated C code in equivalence tests. For more information, see Generate Cobertura Coverage Reports for Generated C Code in Equivalence Tests.
Export code quality metrics from the Code Quality Dashboard by using the API
Update, retrieve, and export the code quality metrics from the Code Quality Dashboard by using these functions:
Improved performance for execute
function in C/C++ equivalence tests (R2024a Update)
The execute function shows improved performance
when executing generated C/C++ code in equivalence tests in test classes that inherit from
matlabtest.coder.TestCase. For example, the equivalence test
tEquivalence uses parameterized inputs to run the test 49 times with
different input permutations. The execute function executes the generated C
code approximately 11x faster than in the R2024a general
release:
classdef tShortestPathEquivalence < matlabtest.coder.TestCase properties BuildResults; AdjMatrix; end properties(TestParameter) StartIdx = {-1,0,1,2,3,4,5}; EndIdx = {-1,0,1,2,3,4,5}; end methods(TestClassSetup) function generateCode(testCase) testCase.AdjMatrix = [0, 1, 0, 1, 0; 1, 0, 1, 0, 1; 0, 1, 0, 1, 0; 1, 0, 1, 0, 1; 0, 1, 0, 1, 0]; startIdx = -1; endIdx = 2; inputs = {testCase.AdjMatrix,startIdx,endIdx}; functionToBuild = "shortest_path.m"; testCase.BuildResults = build(testCase,functionToBuild, ... Inputs=inputs,Configuration="lib"); end end methods(Test) function tEquivalence(testCase,StartIdx,EndIdx) inputs = {testCase.AdjMatrix,StartIdx,EndIdx}; executionResults = execute(testCase, ... testCase.BuildResults,Inputs=inputs); verifyExecutionMatchesMATLAB(testCase,executionResults); end end end
R2024a General Release: 44.26 s
R2024a Update 5: 3.91 s
The code was timed on a Windows® 10, Intel® Xeon ® Gold 6240 CPU @ 2.60GHz system by using
the timeit
function:
timeit(@() runtests("tShortestPathEquivalence"))execute function was calculated by timing the test, timing
the test with the execute function commented out, and comparing the
results.In the generateCode test class setup function in the
tShortestPathEquivalence test class, the C code generates from the
shortest_path function. To open the function, execute this
code:
openExample matlabtest/ShortestPathExample edit shortest_path