Matlab_xunit , using globals in my test cases
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Neesha
le 6 Fév 2015
Réponse apportée : Image Analyst
le 14 Fév 2015
Hi All,
I am writing some testcases. Here is a question about what is the right programming practice.
The function i want to write the test case for is using a couple of globals (and there will be some which are using 5-6 globals or more hence I want to do it with right way) but those globals are not being passed to the function since it is globla (duh! ) just used inside the function.
So to write the test case I have to declare the globals in test case as well and I am not sure If that is good practice. If not, what is the right way to do it?
Here is an example I created for you , it is not an actually program
my main program...
function [numbers] = calcAll(text)
global gNum
if strcmp(text, 'Add')
numbers = gNum + 3;
else
numbers = gNum * 3;
end
end
Now my test case would be something like this
function [] = testingCalcAll()
global gNum = load('global.mat'); % Saved global.mat for testing
goldNumbers = load('output.mat'); % i have output of calcAll() saved here
testNumbers = calcAll('Add');
if ~isequal(goldNumbers, testNumbers)
TestCaseStatus = 'FAIL'
else
TestCaseStatus = 'PASS'
end
end
So again the question is, is it all right to have global like gNum in my testingCalcAll()? Or is there a better way to do it?
Thanks
0 commentaires
Réponse acceptée
Image Analyst
le 14 Fév 2015
I never assign the global on the same line as I declare it.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Testing Frameworks 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!