matlab.unittest.qualifications.Verifiable.verifyTrue - Verify value is true - MATLAB (original) (raw)

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

Syntax

Description

verifyTrue([testCase](#bt00rlt-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F7864e98e-1c9c-41ad-b639-eccaba0b426c)) verifies that the value of actual is logical 1 (true).

example

verifyTrue([testCase](#bt00rlt-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F7864e98e-1c9c-41ad-b639-eccaba0b426c),[diagnostic](#mw%5F8d4a3c67-ebb4-43f4-b4a8-a1f0f805d9e3)) 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 a value of any data type. Although you can provide a value of any data type, the test fails if actual is not a logical scalar with a value of true.

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 true.

verifyTrue(testCase,true)

Test false.

verifyTrue(testCase,false)

Verification failed. --------------------- Framework Diagnostic: --------------------- verifyTrue failed. --> The value must evaluate to "true".

Actual Value:
  logical

   0
------------------
Stack Information:
------------------
In C:\work\TestMATLABLogicalFunctionsExample.m (TestMATLABLogicalFunctionsExample) at 16

When you test using verifyTrue, the test fails if the actual value is not of type logical.

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Test the value 1. The test fails because the value is of type double.

verifyTrue(testCase,1,"Value must be a logical scalar.")

Verification failed. ---------------- Test Diagnostic: ---------------- Value must be a logical scalar. --------------------- Framework Diagnostic: --------------------- verifyTrue failed. --> The value must be logical. It is of type "double".

Actual Value:
     1
------------------
Stack Information:
------------------
In C:\work\TestANonzeroNumericValueExample.m (TestANonzeroNumericValueExample) at 14

When you test using verifyTrue, the test fails if the actual value is nonscalar.

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Test the value [true true]. The test fails because the value is nonscalar.

verifyTrue(testCase,[true true])

Verification failed. --------------------- Framework Diagnostic: --------------------- verifyTrue failed. --> The value must be scalar. It has a size of [1 2].

Actual Value:
  1×2 logical array

   1   1
------------------
Stack Information:
------------------
In C:\work\TestLogicalArraysExample.m (TestLogicalArraysExample) at 15

Tips

Version History

Introduced in R2013a