matlab.unittest.qualifications.Verifiable.verifyNotEmpty - Verify value is not empty - MATLAB (original) (raw)

Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications

Verify value is not empty

Syntax

Description

verifyNotEmpty([testCase](#bt00qzq-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F244a732a-04be-434e-8bca-f9a7726af4a3)) verifies that actual is a nonempty MATLAB® array.

example

verifyNotEmpty([testCase](#bt00qzq-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F244a732a-04be-434e-8bca-f9a7726af4a3),[diagnostic](#mw%5F4440121b-248d-42fa-b847-42050f3d92bb)) also associates the diagnostic information in diagnostic with the qualification.

example

Input Arguments

expand all

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 an array of any data type.

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

expand all

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Test an empty character vector. The test fails.

verifyNotEmpty(testCase,'')

Verification failed. --------------------- Framework Diagnostic: --------------------- verifyNotEmpty failed. --> The value must not be empty. --> The value has a size of [0 0].

Actual char:
  0×0 empty char array
------------------
Stack Information:
------------------
In C:\work\TestForNonemptyCharacterVectorsExample.m (TestForNonemptyCharacterVectorsExample) at 12

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Verify that the vector [2 3] is not empty. The test passes.

verifyNotEmpty(testCase,[2 3])

Test if an array with a zero dimension is not empty. The test fails because an array with any zero dimension is empty.

verifyNotEmpty(testCase,ones(2,5,0,3))

Verification failed. --------------------- Framework Diagnostic: --------------------- verifyNotEmpty failed. --> The value must not be empty. --> The value has a size of [2 5 0 3].

Actual Value:
  2×5×0×3 empty double array
------------------
Stack Information:
------------------
In C:\work\TestForNonemptyNumericArraysExample.m (TestForNonemptyNumericArraysExample) at 17

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Verify that a cell array containing empty numeric arrays is not empty.

verifyNotEmpty(testCase,{[],[],[]})

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Create and test an empty test suite. The test fails.

emptyTestSuite = matlab.unittest.TestSuite.empty; verifyNotEmpty(testCase,emptyTestSuite,"Value must be nonempty.")

Verification failed. ---------------- Test Diagnostic: ---------------- Value must be nonempty. --------------------- Framework Diagnostic: --------------------- verifyNotEmpty failed. --> The value must not be empty. --> The value has a size of [0 0].

Actual Value:
  0×0 TestSuite array with no properties.
------------------
Stack Information:
------------------
In C:\work\TestForNonemptyTestSuitesExample.m (TestForNonemptyTestSuitesExample) at 13

Tips

Version History

Introduced in R2013a