How to publish the "matlab.un​ittest.Tes​tResult" objects to a PDF report?

7 ビュー (過去 30 日間)
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?

採用された回答

MathWorks Support Team
MathWorks Support Team 2023 年 5 月 3 日
編集済み: MathWorks Support Team 2023 年 5 月 3 日
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":
  • Run below command in MATLAB 2016b for documentation:
>>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 件)

カテゴリ

Help Center および File ExchangeResults, Reporting, and Test File Management についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by