Create test runner from cell array of function handles and arguments and overwrite failure summary text
1 回表示 (過去 30 日間)
古いコメントを表示
Hi I have implemented a mother test class which inherits from matlab.unittest.TestCase. This test class has two methods, one of which allows adding test functon handles (and its arguments) to a test array and the other allows to run said array.
function myTest(this) % In daughter class
% Add as many test pre-requesites as needed
this.addTestPrereq(@verifyEqual, this, uint8(19), uint8(18), 'Val1 and Val2 are not equal');
...
% Check all pre-requesites
this.checkAllTestPrereq();
...
% Actual test
this.verify...
end
function [] = addTestPrereq(this, fctHdl, varargin) % In motherclass
...
% Save handle to 1st column
this.testPrereqArr{this.numPrereq, 1} = fctHdl;
this.testPrereqArr{this.numPrereq, 2} = varargin;
end
function resFlag = checkAllTestPrereq(this) % In motherclass
...
for iTest = 1:this.numPrereq
tstHdl = this.testPrereqArr{iTest, 1};
tstArg = this.testPrereqArr{iTest, 2};
% Execute test
tstHdl(tstArg{:});
end
resFlag = this.isAllTestValid();
% Stop in case not all tests were valid
this.assertTrue(...);
end
The idea is to ensure a specific configuration before running the test and segregate the conditions from the actual test. This works well. However, I would like to go further. I wanted to know if I can combine these function handles (and their arguments) into a test runner and customize the failure summary for that test runner. IDeally i would like to hide the framework diagnostic for it as well.
I tried functiontests but it didnt consider these handles to be local functions. All the handles are within either the daughter or the mother class.
Thank you
0 件のコメント
回答 (1 件)
Andy Campbell
2019 年 1 月 8 日
I may be missing something, but this seems like something you don't need to do at all. Rather I would suggest using Assumptions or Assertions directly rather than putting them behind the function handles. You would want to use an assumption if you want to filter the test if the preconditions aren't met, and and assertion if you want to fail and not even run the rest of the test.
Here is more information on the types of qualifications:
Hope that helps!
Andy
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Write Unit Tests についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!