Baseline test - Is it possible to use relative path instead of absolute when adding baseline criteria?

4 visualizaciones (últimos 30 días)
I have a problem when sharing my test files - mldatx files containing Baseline tests with other users. The problem is that when I add a Baseline criteria .mat file inside a Baseline test (via Test Manager tool), it creates an absolute path to this .mat file based on the path on my machine. When I share this Test File with other users, they cannot run the test because their absoulte path to .mat file is different than mine.
My question is: Is it possible to somehow add a relative path to a .mat file as Baseline criteria, which could then be loaded on every machine because it's tied to the relative path only, not absolute?
Thank you!

Respuesta aceptada

Gayatri
Gayatri el 2 de Abr. de 2024
Hi Petar,
One way to handle this is by leveraging the ‘preLoadFcn’ property of your test cases. This property allows you to specify a function that runs before your test executes. It will dynamically set the path to your MAT file relative to the location of your test file.
1. Create a Preload Function: Write a function that calculates the path to your MAT file relative to the common base directory and sets this path in a way that your test can use it.
function preloadFunction(testCase)
% Example of setting a relative path for a MAT file
basePath = fileparts(which('yourTestFile.m'));
relativePathToMat = fullfile(basePath, 'relative', 'path', 'to', 'yourMatFile.mat');
testCase.TestData.matFilePath = relativePathToMat;
end
2. Configure Your Test to Use the Preload Function: In the Test Manager or your test script, set the ‘preLoadFcn’ property of your test case to point to the preload function you just created.
Please refer the below documentation for ‘preLoadFcn’ property: https://in.mathworks.com/help/simulink/ug/model-callbacks.html
I Hope it helps!
  1 comentario
Petar
Petar el 2 de Abr. de 2024
Hello Gayatri,
Thank you very much! With your inputs and suggestions I was able to solve my problem and set a relative path for my baseline criteria, so it is solved now.
Kind regards,
Petar

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by