Inserting a comment before the pdf report of the execution of a matlab.unittest.TestCase function
1 回表示 (過去 30 日間)
古いコメントを表示
I have not been able to find the solution to this anywhere: I have a Testcase class, containing several functions that relate to all the individual tests I wish to perform on a Simulink model. The results of each individual test is logged accordingly in a pdf obtained using a different script.
What I wish to do is add a comment before the execution of each individual function in the test case. I'll provide a picture of both the current execution of our code, as well as what I wish to do:
My code for the Testcase class:
classdef tests_HIL_ADF < matlab.unittest.TestCase
methods(Test)
function SC001_SN001_SN002(testCase)
global in_test;
load('SC001_SN001_SN002_in.mat');
load('SC001_SN001_SN002_out.mat');
simulation_out = sim('my_open_simulink_model',400);
sim_out = struct(simulation_out);
oracle = struct(OUT_Test);
simulation_time = (1:1:length(oracle.Data.ADF_Static_Q_Valid));
import matlab.unittest.diagnostics.FigureDiagnostic
f = figure;
plot(simulation_time, sim_out.Data.ADF_Static_Q_Valid(simulation_time), simulation_time, oracle.Data.ADF_Static_Q_Valid); grid on
legend("Simulation Output", "Oracle");
testCase.verifyEqual(uint8(sim_out.Data.ADF_Static_Q_Valid(simulation_time)), uint8(oracle.Data.ADF_Static_Q_Valid), 'RelTol', 0.1, ["ADF_Static_Q_Valid", FigureDiagnostic(f,'Prefix','SC001_SN001_SN002_ADF_Static_Q_Valid','Formats','png')]);
close(f);
f = figure;
plot(simulation_time, sim_out.Data.Train_Info_Q_Valid(simulation_time), simulation_time, oracle.Data.Train_Info_Q_Valid); grid on
legend("Simulation Output", "Oracle");
testCase.verifyEqual(uint8(sim_out.Data.Train_Info_Q_Valid(simulation_time)), uint8(oracle.Data.Train_Info_Q_Valid),'AbsTol',1, ["Train_Info_Q_Valid", FigureDiagnostic(f,'Prefix','SC001_SN001_SN002_Train_Info_Q_Valid','Formats','png')]);
close(f);
end
% more functions with different variables go here
end
end
The code used to run the script and generate the PDF file:
import matlab.unittest.TestRunner
import matlab.unittest.TestSuite
import matlab.unittest.plugins.TestReportPlugin
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoverageReport
global in_test;
suite = TestSuite.fromFile('tests_HIL_ADF.m');
runner = TestRunner.withTextOutput;
pdfFile = strcat('tests_HIL_ADF.pdf');
plugin = TestReportPlugin.producingPDF(pdfFile,...
'IncludingPassingDiagnostics',true,'IncludingCommandWindowText',true,...
'LoggingLevel', 4);
runner.addPlugin(plugin);
result = runner.run(suite)
Its output:
What I WISH to see in the output:
Any idea how I can get that "Comments" section to print out for each function in the resulting PDF? Even if it's weird workarounds, I'm okay either way.
0 件のコメント
回答 (1 件)
Malay Agarwal
2023 年 7 月 12 日
Hi Marco,
Please take a look at this resource and see if it helps you out: Plugin to Generate Custom Test Output Format - MATLAB & Simulink - MathWorks India. You need to create a custom plugin that adds the comments into the report. Please revert back if this doesn't help.
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Results, Reporting, and Test File Management についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!