Let's say I've written a MEX function, foo, that when given the number 5 throws an error.
Inside the mex function, the code would look something like:
if (inputValue == 5)
sprintf_s(errMsg, "ERROR: input was %d, and so I'll throw an error", inputValue);
Now, if I call foo(5), this error will be thrown.
I cannot seem to figure out how to write a unit test to verify this!
err_msg = 'ERROR';
I cannot seem to substitute anything in for the 'err_msg' variable in my example to get the test to pass!
Interestingly enough, when err_msg has some string, the test throws the feedback:
ERROR (<- whatever the value of the variable 'err_msg' is from my example)
Yet when I make err_msg an empty string, the test fails as incomplete with the messages:
Uncaught error occurred in Foo_Test/Verify_Foo_Throws_Error.
The remainder of the test method will not run to completion.
Error using matlab.unittest.constraints.Throws (line 161)
Expected exception to be a row vector.
Error in matlab.unittest.internal.qualifications.QualificationDelegate/qualifyError (line 152)
throws = delegate.decorateConstraintAlias(Throws(errorClassOrID),'Error');
Error in matlab.unittest.qualifications.Verifiable/verifyError (line 687)
Error in Foo_Test/Verify_Foo_Throws_Error (line 138)
Any assistance would be most appreciated. Thanks!