フィルターのクリア

Customise test report generated by matlab.uni​ttest.Test​Case.gener​atePDFRepo​rt method

7 ビュー (過去 30 日間)
Hi,
I am using matlab.unitTest.TestCase.generatePDFReport method to generate my testReport. I see that the report contains the failure/pass or some diagnostics from the command window only. I want to add some piecharts or some messages to the report, is it possible?
Thanks in advance.

採用された回答

T.Nikhil kumar
T.Nikhil kumar 2024 年 2 月 13 日
Hello Harish,
As of today, I think the ‘generatePDFReport’ method in MATLAB does not support the inclusion of custom content such as pie charts or additional messages within the generated PDF report.
I would suggest you to try creating your own reporting mechanism by leveraging the MATLAB Report Generator.
You could obtain the results of the tests in the form of ’matlab.unittest.TestResult’ array using the ‘runtests’ function. Based on these test results, create pie charts using MATLAB's plotting functions. You can also prepare custom messages you wish to include in the report. You can then save these figures as image files.
You can now use MATLAB Report Generator ('mlreportgen.report.Report'), to create a custom PDF report. Please go through the content generation page to learn about adding figures and messages to your report. Refer to the below example of adding a figure and custom message to your report:
% Generate your pie chart
figure;
pie([0.5 0.25 0.25])
%saving figure as image
saveas(gcf, 'testResultsPieChart.png');
% Create a custom report
import mlreportgen.report.*;
rpt = Report('MyTestReport', 'pdf');
% Add a title page and table of contents
titlepg = TitlePage;
titlepg.Title = 'My Test Results';
titlepg.Author = 'Your Name';
add(rpt, titlepg);
add(rpt, TableOfContents);
% Add custom messages or results
add(rpt, Paragraph('Some custom message'));
% Add the pie chart to the report
fig = Image('testResultsPieChart.png');
fig.Width = '4in';
fig.Height = '3in';
add(rpt, fig);
% Close and view the report
close(rpt);
rptview(rpt);
Refer to the following documentation to understand more about the functions mentioned above:
MATLAB Report Generator - https://www.mathworks.com/help/rptgen
Content Generation in MATLAB Report Generator - https://www.mathworks.com/help/rptgen/content-generation.html
Hope this helps you proceed further!

その他の回答 (1 件)

Mattia Marsetti
Mattia Marsetti 2024 年 3 月 14 日
Hi Harish
You can use the FigureDiagnostic class to add a custom artifact that will print together with the test as in the following example, where I have defined a simple test class, with a unique test method which will always fail and report a figure as diagnostic.
Please note that instead of "fdiag" you can have a different diagnostic or a simple text that will be reported in the final pdf report. See documentation here: https://it.mathworks.com/...diagnostic
classdef myTestCase < matlab.unittest.TestCase
methods(Test)
function test_with_diag_figure(testCase)
f=figure;
spy;% plot your custom chart here
fdiag=FigureDiagnostic(f,'Formats',{'png'},'Prefix','LoggedFigure_');
testCase.log(1,fdiag);% if you want to always log the figure in the test, even if it passes
testCase.verifyLessThan(1,0,fdiag);% this will add the figure as a detailed diag in case of failure
end
end
end
Is it what you where looking for?

カテゴリ

Help Center および File ExchangeManual Performance Optimization についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by