Borrar filtros
Borrar filtros

Matlab_xunit , using globals in my test cases

2 visualizaciones (últimos 30 días)
Neesha
Neesha el 6 de Feb. de 2015
Respondida: Image Analyst el 14 de Feb. de 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

Respuesta aceptada

Image Analyst
Image Analyst el 14 de Feb. de 2015
I never assign the global on the same line as I declare it.

Más respuestas (0)

Categorías

Más información sobre Testing Frameworks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by