创建 IsSupportedTest 测试用例。在此示例的后续步骤(高亮文件中的特定函数)中,请参阅以下 IsSupportedTest 测试用例。
classdef IsSupportedTest < matlab.unittest.TestCase
methods(TestClassSetup)
function TestPlatform(testcase)
testcase.assumeFalse(ispc,...
'Do not run any of these tests on Windows.')
end
end
methods(Test)
function test1(testcase)
% write test code here
end
end
end
要在此示例中执行 MATLAB® 命令,请将 IsSupportedTest.m 文件添加到 MATLAB 路径上的文件夹。
编写测试以验证平台。此测试用例中的所有测试只能在 UNIX® 平台上运行。TestPlatform 函数使用 assumeFalse 方法测试 MATLAB 是否运行于 Windows® 平台上。如果是,则测试失败。
function TestPlatform(testcase)
testcase.assumeFalse(ispc,...
'Do not run any of these tests on Windows.')
end
将 TestPlatform 设置为 TestClassSetup 测试。要使 TestPlatform 测试成为先决条件,请将其添加到 methods (TestClassSetup) 块内部。
运行测试用例。