首页 > 解决方案 > Matlab 测试运行器跳过尝试导入不存在文件的测试函数

问题描述

让我们定义一个简单的测试类

classdef test_file < matlab.unittest.TestCase
    methods(Test)
        function test_function(testCase)
            import some_package.some_function
            testCase.verifyEqual(true,some_function(0));    
        end
    end
end

做什么是无关紧要的some_function。我的路径中不存在函数 some_package.some_function(例如,我在推送提交时忘记添加它)。每当我尝试运行上面的测试文件时,test_function都会跳过测试并发出警告:

Warning: "test_file.m" was excluded.
Caused by:
    Error: File: test_file.m Line: 4 Column: 20
    The import statement 'import sc_force_models.apparent_accel' cannot be found or cannot be imported. Imported names must
    end with '.*' or be fully qualified.

由于跳过了测试,因此未检测到问题,并且测试运行程序返回 0 个错误。如果有人忘记提交文件,我仍然想在测试期间检测到这个问题,所以预期的行为是测试用例失败。

作为一种解决方法,我尝试对 testrunner 使用 'Strict',True 参数,但它既没有检测到问题。我也尝试将 import 语句放在 , 语句之间trycatch但似乎文件中的任何代码都没有执行。

任何想法如何在测试用例中检测不正确的导入语句?

标签: matlab

解决方案


推荐阅读