matlab判断字符串包含字符串,确认字符串包含指定字符串创建供交互测试的 TestCa 对象。
testCa = matlab.unittest.TestCa.forInteractiveU;
测试字符串中是否包含⼦字符串。
verifySubstring(testCa, 'SomeLongMessage', 'Long');
Interactive verification pasd.
展⽰⼤⼩写不同所造成的影响。
verifySubstring(testCa, 'SomeLongMessage', 'lonG');
Interactive verification failed.
---------------------
Framework Diagnostic:
---------------------
verifySubstring failed.
--> The value does not contain the substring.
Actual char:
SomeLongMessage
Expected Substring:
lonG
测试失败。
通过测试实际字符串中不包含的⼦字符串致使确认失败。
verifySubstring(testCa, 'SomeLongMessage', 'OtherMessage');
Interactive verification failed.
---------------------
Framework Diagnostic:
---------------------
verifySubstring failed.
--> The value does not contain the substring.
Actual char:
SomeLongMessage
Expected Substring:
OtherMessage
测试失败。
显⽰如果⼦字符串⽐实际字符串长,确认将失败。
verifySubstring(testCa, 'SomeLongMessage', 'SomeLongMessageThatIsLonger');
Interactive verification failed.
---------------------
Framework Diagnostic:
---------------------
verifySubstring failed.
--> The value does not contain the substring. Actual char:
SomeLongMessage
Expected Substring: SomeLongMessageThatIsLonger
测试失败。