matlab - 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 语句放在 , 语句之间try
,catch
但似乎文件中的任何代码都没有执行。
任何想法如何在测试用例中检测不正确的导入语句?
解决方案
推荐阅读
- python - 尝试使用 SQL 和 discord.py 制作一个警告命令,该命令可以显示用户被警告了多少次
- spring-boot - Nginx、spring boot hello world 和 example.com
- python - matplotlib plot x 轴未缩放到 x 轴数组
- php - 如何仅在商店页面上使用 CSS 将我的购物车隐藏在菜单中?
- uart - 修复了lora e32 ebyte之间的传输-micropython
- search - 计算二叉搜索树中项目的出现次数
- mysql - 如何查看 Apache OFBiz 的数据库,以及如何将其传输到在 GCP 上运行的 MySQL 数据库?
- c++ - 为什么当我使用 std::filesystem::directory_terator 迭代目录时有时会调用 abort() 方法?
- sed - 使用重命名 sed 从文件名中减去
- python - Numpy 连接给出错误:轴 1 超出维度 1 数组的范围