Write Unit test for InputException Error Test in Magento 2.

You can write a  Unit test to check the InputException error text message matched or not using assertEquals() or assertStringMatchesFormat() method for an input exception error.

Let’s take a simple example with a function,

Now we have to verify Input exception string with PHP unit test,
We have to create a Test file inside the Test\Unit folder of the module.

For InputException, Value will be dynamically added using  ‘%1’ format.

Under the ClassnameTest.php file, add below function to verify Test case,

Based on the above test case you need to run the Unit test and Your unit test will be successful.

We have test the InputException with assertEquals() and  assertStringMatchesFormat() assertion.

For Unit test basic check link, What is a Unit test in Magento 2?