MATLAB Answers

BdS
0

Unit tests with verifyError

Asked by BdS
on 1 Nov 2018
Latest activity Edited by per isakson
on 2 Nov 2018
Hello, I am trying to unit test the error message in the function below, which pops up if I input an incorrect fieldname: 'ALTMAN_T_SCORE' instead 'ALTMAN_Z_SCORE'.
My function:
function [CorrectFields]=FieldValidity(fieldNames,FieldDescrip)
check=FieldDescrip;
[badFld,indBadFld]=ismember('BAD_FLD',check(:,2));
if badFld
error('Bad field identifier entered: %s not found.',fieldNames{indBadFld})
else
CorrectFields=fieldNames;
end
end
And the unit test function which according to Matlab is incorrect:
function testFieldsAreInvalid(testCase)
a={'ALTMAN_T_SCORE';'BEST_ROE';'PX_LAST';'PX_VOLUME'};
aa={'Discription','BAD_FLD','ALTMAN_T_SCORE','Altman''s Z-Score';'Discription','BE014','BEST_ROE','BEst ROE';'Discription','PR005','PX_LAST','Last Price';'Discription','PR013','PX_VOLUME','Volume'};
actSolution=FieldValidity(a,aa);
verifyError(testCase,actSolution,'Bad field identifier entered: ALTMAN_T_SCORE not found.')
end
The error message is: Error occurred in getBbgFieldDataTest/testFieldsAreInvalid and it did not run to completion.
---------
Error ID:
---------
''
--------------
Error Details:
--------------
Error using FieldValidity (line 7)
Bad field identifier entered: ALTMAN_T_SCORE not found.
Error in getBbgFieldDataTest>testFieldsAreInvalid (line 67)
actSolution=FieldValidity(a,aa);
================================================================================
.
Done getBbgFieldDataTest
__________
Failure Summary:
Name Failed Incomplete Reason(s)
=========================================================================
getBbgFieldDataTest/testYesWarning X X Errored.
-------------------------------------------------------------------------
getBbgFieldDataTest/testFieldsAreInvalid X X Errored.
I would appreciate your help. Thank you in advance.

  0 Comments

Sign in to comment.

0 Answers