Run MATLAB Test Suite from Azure Pipeline.yml
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; "
|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; "
| 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; "
| matlab, simulink, azure, ci/cd, test, pipeline MATLAB Answers — New Questions