Pass data directory input argument to a set of unit tests
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Have created a class-based unit test and test runner function. Want to execute on several datasets with each dataset located in separate directories. Tried to pass an input argument but cannot figure out how to pass to RUN function and in the classdef function. Any suggestions? Below are my program.
function results = testRunner( dataFoldername )
% Number of Arguments Checks
% Input Arguments
narginchk( 1, 1 );
% Output Arguments
nargoutchk( 1, 1 );
% Data Input Pathname
currentFolder = pwd;
dataPathname = sprintf( '%s%s%s', currentFolder, filesep, dataFoldername );
% Run Unit Tests
testCase = testGantryMotionRTS;
results = run( testCase );
classdef testGantryMotionRTS < matlab.unittest.TestCase
% Test Method Block
methods ( Test )
% Test Function 1
function testBalanceSensorResponseSolution1( testCase )
% Expected Results
expectedResults = waveformcsvread;
% Actual Results
actualResults = rtscsvread( 'balancesensorresponsetopic' );
% Verify Using Test Qualification
for i = 1:length( expectedResults )
actualSolution = actualResults.rotation_time;
expectedSolution = expectedResults.rotation_time;
testCase.verifyEqual( actualSolution, expectedSolution );
actualSolution = actualResults.sensor_data.x_data;
expected
actualSolution = actualResults.sensor_data.z_data;
expectedSolution = expectedResults.sensor_data.z_data;
testCase
actualSolution = actualResults.sensor_data.gantry_position_in_degrees;
expectedSolution = expectedResults.sensor_data.gantry_position_in_degrees;
testCase.verifyEqual( actualSolution, expectedSolution );
end
end
end
end
Thank you
Ariel Friedlander
1 commentaire
Réponses (2)
Steven Lord
le 8 Jan 2019
Modifié(e) : Steven Lord
le 8 Jan 2019
One way to do this would be with a parameterized test, either by having your test call a function that returns the parameter values (the list of data sets) or (if you're using release R2018b or later) using an external parameter that you inject when you execute the test. An example of the former:
classdef testExist < matlab.unittest.TestCase
properties(TestParameter)
listOfFilesInPWD = getAllFilesInPwd;
end
methods(Test)
function existShouldFindFilesInCurrentDirectory(testcase, ...
listOfFilesInPWD)
testcase.verifyNotEqual(exist(listOfFilesInPWD), 0)
end
end
end
function y = getAllFilesInPwd
d = dir;
y = {d.name};
end
0 commentaires
Luna
le 8 Jan 2019
Hi Ariel,
You can't define a class and a function which is not a method of the class in the same .m file.
Please read below link to create a user based unit test classes and built-in packages:
0 commentaires
Voir également
Catégories
En savoir plus sur Write Unit Tests dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!