how do I perform follow up tasks after failure

1 visualizzazione (ultimi 30 giorni)
Hi,
I developed a unittest framework using matlab.unittest.testCase class. I want to perform some actions after a certain test passes or fails.
testCase.VerifyEqual(actualValue, ecxpectedValue);
%if failed perform may be the following
testCase.failureCount = testCase.failureCount +1 ;
How do I do this? I tried usinng onFailure method by adding some function, but that is not working as expected.
the following didn't work as expected
testcase.onFailure(@() functionCallOnFailure())
Can anyone answer this?
thanks in advance.

Risposta accettata

akshatsood
akshatsood il 5 Feb 2024
Modificato: akshatsood il 5 Feb 2024
I understand that you seek guidance on performing follw up tasks after a certain function pases or fails. When writing tests, it is often useful to provide additional information that can help diagnose the reason for a test failure. You should look upto the "diagnostic" argument available while calling "verifyEqual".
verifyEqual(testCase,actual,expected,diagnostic)
where "diagnostic" can be a string, character vector, function handle, or "matlab.unittest.diagnostics.Diagnostic" object that provides additional information when a test fails. The "diagnostic" argument allows you to specify a custom message or a diagnostic procedure to run when "verifyEqual" determines that "actual" does not match "expected". This can greatly aid in understanding the context and cause of test failures.
For your use case, you have the option to provide function handles that facilitate any subsequent actions you require. Should you encounter any challenges, please do not hesitate to reach out for assistance.
I hop this helps

Più risposte (0)

Categorie

Scopri di più su Extend Testing Frameworks in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by