Run MATLAB Test Suite from Azure Pipeline.yml

21 views (last 30 days)
Dear community,
I would like to run test suites from an azure-pipelines.yml. Unfortunately I lack the correct commands to do so and whenever the pipeline reaches the step to run the testmanager I receive an error, that 'import' is not recognized as internal or external command (see below, unfortunately I cannot add it as code here as it is not matlab code). A link for the MATLAB documentation regarding this topic is found here: MATLAB - Visual Studio Marketplace. Thus far I did not find any related topic on this platform. I am sorry that the .yml code cannot be posted in a code block as well. Maybe you have some suggestions/ corrections that can help here?
- task: InstallMATLAB@1
inputs:
release: R2024a
products: >
Simulink
Simulink_Test
Code_Coverage
displayName: Install MATLAB R2024a + Simulink Toolboxes
[...some MATLAB server connection steps...]
- script: |
echo "Initializing MATLAB project"
matlab -batch "run('model/init_my_model.m')"
workingDirectory: '$(Pipeline.Workspace)/self'
displayName: 'Initialize MATLAB Project'
- script: |
echo "Setting up test environment"
matlab -batch "run('model/05_etc/my_test_environment.m')"
workingDirectory: '$(Pipeline.Workspace)/self'
displayName: 'Set Up Test Environment'
# This is the step that causes trouble
- task: RunMATLABCommand@1
inputs:
command: |
% Run MATLAB tests and generate PDF report
import matlab.unittest.TestSuite;
import matlab.unittest.TestRunner;
import matlab.unittest.plugins.TestReportPlugin;
suite = TestSuite.fromFile('model/05_etc/test_manager.mldatx');
runner = TestRunner.withTextOutput;
pdfFile = 'model/05_etc/sw_mil_report.pdf';
runner.addPlugin(TestReportPlugin.producingPDF(pdfFile));
result = runner.run(suite);
displayName: 'Run MATLAB Test Manager'
- script: |
echo "Checking if PDF report exists"
if exist "model/05_etc/sw_mil_report.pdf" (
echo "PDF report found. Moving to artifact staging directory."
mkdir $(Build.ArtifactStagingDirectory)/test_results
move "model/05_etc/sw_mil_report.pdf" $(Build.ArtifactStagingDirectory)/test_results/
) else (
echo "PDF report not found."
exit 1
)
workingDirectory: '$(Pipeline.Workspace)/self'
displayName: 'Find and Save Test Results PDF'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/test_results'
artifact: 'test_results'
displayName: 'Publish Test Results as Artifact'
------------------------------------------
Here is the error from the pipeline run:
"Running MATLAB tests and generating PDF report"
import matlab.unittest.TestSuite; "
|
  1 Comment
Peter
Peter on 2 Oct 2024
Edited: Peter on 2 Oct 2024
So it seems that the test manager file is not supported? {Error using matlab.unittest.internal.services.fileextension.FileExtensionService/fulfill (line 32)
"C:\Users\adm.codeanalysis\Downloads\vsts-agent-win-x64-3.220.0\_work\16/self/model/05_etc/test_manager.mldatx" is not a supported file.
Error in matlab.unittest.TestSuite>fromFileServiceLocation (line 944)
fulfill(services, liaison);
Error in matlab.unittest.TestSuite.fromFileCore_ (line 693)
[liaison, supportingService] = fromFileServiceLocation(testFile);
Error in matlab.unittest.TestSuite.fromFile (line 178)
suite = TestSuite.fromFileCore_(testFile, modifier, externalParameters);
Error in command_8296e71b_69bd_4bad_924e_1de2bcc44d23 (line 6)
suite = TestSuite.fromFile('C:\Users\adm.codeanalysis\Downloads\vsts-agent-win-x64-3.220.0\_work\16/self/model/05_etc/test_manager.mldatx');
}
ERROR: MATLAB error Exit Status: 0x00000001
exit status 1

Sign in to comment.

Accepted Answer

Swastik Sarkar
Swastik Sarkar on 16 Oct 2024
Hi @Peter,
It appears that the unittest libraries of MATLAB are being used to run Simulink tests. However, the sltestmanager should be utilized for executing such tests. The following code demonstrates how to run a .mldatx test file:
sltest.testmanager.run('model/05_etc/test_manager.mldatx');
For more detailed information on running a Simulink Test using the Test Manager, please refer to the documentation below:
Hope this helps.

More Answers (0)

Categories

Find more on Results, Reporting, and Test File Management in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!