matlab.unittest.qualifications.Verifiable.verifyWarningFree - Verify function issues no warnings - MATLAB (original) (raw)
Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications
Verify function issues no warnings
Syntax
Description
verifyWarningFree([testCase](#bt00rq7-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F075a8a7e-8860-442f-8532-d104306d1fef))
verifies that actual
is a function handle that issues no warnings.
verifyWarningFree([testCase](#bt00rq7-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F075a8a7e-8860-442f-8532-d104306d1fef),[diagnostic](#mw%5F18707def-3fac-450e-bfc2-05e8870004d5))
also associates the diagnostic information in diagnostic
with the qualification.
`[output1,...,outputN]` = verifyWarningFree(___)
also returns any outputs produced when the function handle is invoked. You can use any of the input argument combinations in the previous syntaxes.
Input Arguments
Test case, specified as a matlab.unittest.qualifications.Verifiable
object. Because the matlab.unittest.TestCase class subclasses matlab.unittest.qualifications.Verifiable
and inherits its methods, testCase
is typically amatlab.unittest.TestCase
object.
Value to test, specified as a value of any data type. Although you can provide a value of any data type, the test fails if actual
is not a function handle.
Example: @() myFunction(1,2)
Example: @() mkdir("myFolder")
Diagnostic information to display when the qualification passes or fails, specified as a string array, character array, function handle, or array of matlab.automation.diagnostics.Diagnostic objects.
Depending on the test runner configuration, the testing framework can display diagnostics when the qualification passes or fails. By default, the framework displays diagnostics only when the qualification fails. You can override the default behavior by customizing the test runner. For example, use a DiagnosticsOutputPlugin instance to display both failing and passing event diagnostics.
Example: "My Custom Diagnostic"
Example: @dir
Examples
Test if the actual value is a function handle that issues no warnings.
Create a test case for interactive testing.
testCase = matlab.unittest.TestCase.forInteractiveUse;
Verify that a call to true
does not result in any warnings.
verifyWarningFree(testCase,@true)
Repeat the test with the false
function. Examine the output of the function.
f = verifyWarningFree(testCase,@false)
Verification passed.
f =
logical
0
Verify that a call to size
with an empty array does not result in any warnings.
verifyWarningFree(testCase,@() size([]))
Verify that the test fails if the actual value is not a function handle.
verifyWarningFree(testCase,5,"Value must be a function handle.")
Verification failed. ---------------- Test Diagnostic: ---------------- Value must be a function handle. --------------------- Framework Diagnostic: --------------------- verifyWarningFree failed. --> The value must be an instance of the expected type.
Actual Class:
double
Expected Type:
function_handle
Actual Value:
5
------------------
Stack Information:
------------------
In C:\work\TestForWarningsExample.m (TestForWarningsExample) at 27
Test a function that produces a warning. The test fails.
verifyWarningFree(testCase,@() warning("SOME⚠️id","Warning!"))
Warning: Warning! Verification failed. --------------------- Framework Diagnostic: --------------------- verifyWarningFree failed. --> The function issued warnings.
Warnings Issued:
--> Identifier: "SOME⚠️id"
Message: Warning!
Evaluated Function:
function_handle with value:
@()warning("SOME⚠️id","Warning!")
------------------
Stack Information:
------------------
In C:\work\TestForWarningsExample.m (TestForWarningsExample) at 31
Tips
verifyWarningFree
is a convenience method. For example,verifyWarningFree(testCase,actual)
is functionally equivalent to the following code.
import matlab.unittest.constraints.IssuesNoWarnings
testCase.verifyThat(actual,IssuesNoWarnings)
More functionality is available when using the IssuesNoWarnings constraint directly via verifyThat.- Use verification qualifications to produce and record failures without throwing an exception. Because verifications do not throw exceptions, all test content runs to completion even when verification failures occur. Typically, verifications are the primary qualification for a unit test because they typically do not require an early exit from the test. Use other qualification types to test for violation of preconditions or incorrect test setup:
- Use assumption qualifications to ensure that the test environment meets preconditions that otherwise do not result in a test failure. Assumption failures result in filtered tests, and the testing framework marks the tests as
Incomplete
. For more information, see matlab.unittest.qualifications.Assumable. - Use assertion qualifications when the failure condition invalidates the remainder of the current test content but does not prevent proper execution of subsequent tests. A failure at the assertion point renders the current test as
Failed
andIncomplete
. For more information, see matlab.unittest.qualifications.Assertable. - Use fatal assertion qualifications to abort the test session upon failure. These qualifications are useful when the failure is so fundamental that continuing testing does not make sense. Fatal assertion qualifications are also useful when fixture teardown does not restore the environment state correctly, and aborting testing and starting a fresh session is preferable. For more information, see matlab.unittest.qualifications.FatalAssertable.
- Use assumption qualifications to ensure that the test environment meets preconditions that otherwise do not result in a test failure. Assumption failures result in filtered tests, and the testing framework marks the tests as
Version History
Introduced in R2013a