Main Content

matlab.unittest.constraints.IsFile class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying value points to file

Construction

IsFile creates a constraint specifying that a value is a string scalar or character vector that points to an existing file. The constraint is satisfied if the value is an absolute or relative path to an existing file.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.

Examples

collapse all

Create a test case for interactive testing.

import matlab.unittest.TestCase;
import matlab.unittest.constraints.IsFile;

testCase = TestCase.forInteractiveUse;

Test if myFile.mat is an existing file in your current working folder. This example assumes that the file does not exist and the test fails.

act = 'myFile.mat';
testCase.verifyThat(act,IsFile)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsFile failed.
--> Value does not point to an existing file.
--> Current folder during evaluation:
        'C:\work'

Actual char:
    myFile.mat

In your current working folder, create a folder myFolder that contains a file myTxtFile.txt.

mkdir myFolder
dlmwrite(['myFolder' filesep 'myTxtFile.txt'],rand(5))

Verify that myTxtFile.txt is an existing file in myFolder.

act = ['myFolder' filesep 'myTxtFile.txt'];
testCase.verifyThat(act,IsFile)
Interactive verification passed.

Create a test case for interactive testing.

import matlab.unittest.TestCase;
import matlab.unittest.constraints.IsFile;

testCase = TestCase.forInteractiveUse;

Verify that nonexistentFile.mat is not an existing file in your current working folder. This example assumes that the file does not exist and the test passes.

act = 'nonexistentFile.mat';
testCase.verifyThat(act,~IsFile)
Interactive verification passed.
Introduced in R2018a