フィルターのクリア

Unit tests with verifyError

1 回表示 (過去 30 日間)
BdS
BdS 2018 年 11 月 1 日
編集済み: per isakson 2018 年 11 月 2 日
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by