vendredi 24 août 2018

How do I prevent a Matlab test with "assertWarning" from printing warning text to the console?

I am trying to implement a basic testing framework in Matlab as my first attempt at Test-Driven-Development. One of the tests I am trying to create is intended to verify that my function throws a specific warning under certain input conditions. My code is passing the warning-related tests as intended, however there is a huge annoyance.

When running (and passing) tests involving the "assertWarning" or "verifyWarning" functions, the warnings that are supposed to be triggered are printed to the command window and visually disrupt the printout of my test suite. Is there a way to prevent the (desired) warning from printing to the console only when being run in the tests, while still verifying that the warning is triggered? A sample test function which causes this annoying warning printout is below.

function testAcceleratorMax(testCase)
% Validate that acceleration input is forced to be <=1 and throws warning
state = [0,0,0,0]; input = [2,0];
xd = getPointMass2D_dot(state,input);
assert(isequal(xd,[0,0,1,0]),'Acceleration not ceiled correctly');
verifyWarning(testCase,@(x) getPointMass2D_dot(state,input),...
    'MATLAB:CommandedAccelOutOfBounds');
end

Aucun commentaire:

Enregistrer un commentaire