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

답변 (1개)

Andy Campbell
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

카테고리

Help CenterFile Exchange에서 Write Unit Tests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by