How to call a function if unit test fails?
Ältere Kommentare anzeigen
If this is possible in a script unit test, that would be great. I want to do the following:
%% Unit test
a = 1;
b = 2;
fail = assert(a == b)
if fail
fail_function;
end
fuction fail_function
disp('Test failed');
end
I've also tried finding something to do this using class-based unit testing, but I haven't found anything. Thank you.
1 Kommentar
Walter Roberson
am 30 Jan. 2020
assert() does not permit output assignment.
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 30 Jan. 2020
Bearbeitet: Steven Lord
am 30 Jan. 2020
If all you want your function to do is display a diagnostic message, just modify your call to assert slightly.
%% Unit test
a = 1;
b = 2;
assert(a == b, 'Test failed')
If you want your function to do something else there may be a way to do what you want. One possibility would be to use the diagnostic input to the qualification functions/methods. But it would be difficult to give a more informative answer without more information about what you want to do.
[Forgot assert can't have an output argument when I copied and pasted the example. Removing the output.]
1 Kommentar
John Doe
am 30 Jan. 2020
Kategorien
Mehr zu Write Unit Tests finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!