Run MATLAB Test Suite from Azure Pipeline.yml

14 ビュー (過去 30 日間)
Peter
Peter 2024 年 10 月 2 日
回答済み: Swastik Sarkar 2024 年 10 月 16 日
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 件のコメント
Peter
Peter 2024 年 10 月 2 日
編集済み: Peter 2024 年 10 月 2 日
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

サインインしてコメントする。

採用された回答

Swastik Sarkar
Swastik Sarkar 2024 年 10 月 16 日
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.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by