Create test runner from cell array of function handles and arguments and overwrite failure summary text

1 view (last 30 days)
autre_pensee on 25 Jan 2018
Answered: Andy Campbell on 8 Jan 2019
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
% Actual test
function [] = addTestPrereq(this, fctHdl, varargin) % In motherclass
% Save handle to 1st column
this.testPrereqArr{this.numPrereq, 1} = fctHdl;
this.testPrereqArr{this.numPrereq, 2} = varargin;
function resFlag = checkAllTestPrereq(this) % In motherclass
for iTest = 1:this.numPrereq
tstHdl = this.testPrereqArr{iTest, 1};
tstArg = this.testPrereqArr{iTest, 2};
% Execute test
resFlag = this.isAllTestValid();
% Stop in case not all tests were valid
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

Answers (1)

Andy Campbell
Andy Campbell on 8 Jan 2019
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!

Community Treasure Hunt

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

Start Hunting!

Translated by