- Run below command in MATLAB 2016b for documentation:
How to publish the "matlab.unittest.TestResult" objects to a PDF report?
9 views (last 30 days)
Show older comments
MathWorks Support Team
on 9 Nov 2017
Edited: MathWorks Support Team
on 3 May 2023
How to publish the "matlab.unittest.TestResult" objects to a PDF report?
I'm currently running a combination of MATLAB xUnit-style tests and Simulink Tests from a single MATLAB script using matlab.unittest.TestSuite and matlab.unittest.TestRunner. I'm running the Simulink tests this way so that I can output the results in a JUnit-style XML document using the matlab.unittest.plugins.XMLPlugin. Here's a simple example:
---------------------------------------------------------------------------
>> import matlab.unittest.TestRunner
>> import matlab.unittest.TestSuite
>> import matlab.unittest.plugins.XMLPlugin
>> import matlab.unittest.plugins.ToFile
% Creating test suite from file
>> suite = testsuite('AutopilotTestFile.mldatx');
% Creating a test runner and configuring
>> runner = TestRunner.withTextOutput;
>> xmlFile = 'some_outputs.xml';
>> plugin = XMLPlugin.producingJUnitFormat(xmlFile);
>> runner.addPlugin(plugin);
% Running tests
>> results = runner.run(suite);
---------------------------------------------------------------------------
The results variable is an object of type matlab.unittest.TestResult. The question is that I want to use sltest.testmanager.report to generate a PDF report of the results, but sltest.testmanager.report does not accept matlab.unittest.TestResult objects as arguments. It expects an object of type sltest.testmanager.ResultSet. Is there a way to convert from an array of matlab.unittest.TestResult objects to an object of type sltest.testmanager.ResultSet?
If not, how should I go about publishing the matlab.unittest.TestResult objects to a PDF?
Accepted Answer
MathWorks Support Team
on 3 May 2023
Edited: MathWorks Support Team
on 3 May 2023
One solution is to create a plugin, "TestReportPlugin", that directs the "TestRunner" to produce a test result report in PDF file format. Please refer to the following link for more information on using the plugin, "TestReportPlugin":
>>web(fullfile(docroot,'matlab/ref/matlab.unittest.plugins.testreportplugin-class.html'))
Or for latest release documentation please refer to:
Adding the following lines before running the tests produces the test results report in PDF file format:
>> pdfFile = 'MyTestReport.pdf';
>> pluginPdf = TestReportPlugin.producingPDF(pdfFile,...
'IncludingPassingDiagnostics',true,'IncludingCommandWindowText',true);
>> runner.addPlugin(pluginPdf);
Also, make sure that the "TestReportPlugin" is imported.
0 Comments
More Answers (0)
See Also
Categories
Find more on Results, Reporting, and Test File Management in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!