How to perform multiple identical unit tests.
Mostra commenti meno recenti
Apologies if my question has a relativity simple solution which I have failed to see, but I'm really quite new to the MATLAB unit test framework.
Basically I have a list of over 100 MATLAB scripts that I need to perform the same unit test on. Is there an easy way to do this without having to write out each test individually?
I should also point out that it's important I'm able to see which .m file each test refers to.
Thanks
Risposta accettata
Più risposte (1)
David Hruska
il 7 Mar 2014
1 voto
Release 2014a provides another solution that you may want to consider -- writing a parameterized test. Please see this answer for more details.
2 Commenti
Matlab Pro
il 25 Dic 2023
Here is a specific example that can help you:
This examples calls get_files_to_analyse(), a tests is automatically defined for each file
Yuu do not need to change any of the files
classdef exampleTest < matlab.unittest.TestCase
properties (TestParameter)
files = get_files_to_analyse();
end
methods (Test)
function test1(testCase, files)
results = operate_on_file(files);
testCase.verifyThat(results, <constraint>, ...
sprintf('Testing script %d', i));
end
end
end
%-------------------------------------------------------------
function files = get_files_to_analyse()
base_path_of_files_to_analyse = pwd; % base_path_of_files_to_analyse
d = dir(base_path_of_files_to_analyse);
d = d(~ismember({d.name},{'.','..'})); % remove "." & ".."
files = cellfun(@(x) fullfile(base_path_of_files_to_analyse,x),{d.name}','uni',0);
end
%-------------------------------------------------------------
function operate_on_file(file1)
% do something
end
Matlab Pro
il 25 Dic 2023
please contact for any issue
Categorie
Scopri di più su Script-Based Unit Tests in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!