how do I perform follow up tasks after failure

1 次查看(过去 30 天)
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.

采纳的回答

akshatsood
akshatsood 2024-2-5
编辑:akshatsood 2024-2-5
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Extend Testing Frameworks 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by