필터 지우기
필터 지우기

Matlab_xunit , using globals in my test cases

조회 수: 2 (최근 30일)
Neesha
Neesha 2015년 2월 6일
답변: Image Analyst 2015년 2월 14일
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

채택된 답변

Image Analyst
Image Analyst 2015년 2월 14일
I never assign the global on the same line as I declare it.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Testing Frameworks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by