【问题标题】:MATLAB: How to use "Run Tests" or runtests() commandMATLAB:如何使用“运行测试”或 runtests() 命令
【发布时间】:2018-08-21 07:22:53
【问题描述】:

我使用位于名为“test”的文件夹中的类创建了一个测试脚本 Test1.m。

  classdef Test1 < matlab.unittest.TestCase
  ... code...
  end

我可以通过在命令窗口中输入来运行测试:

run(Test1)

我团队的一些成员熟悉单击“运行测试”按钮(或命令窗口中的 runtests() 等效项)。但是,runtests("Test1.m") 不适用于以下错误:

使用运行测试时出错 不知道要运行什么。尝试“单位”或
“接受”

是文件夹结构的原因吗?我怎样才能使用“运行测试”按钮运行测试脚本。

编辑:

在命令行中执行“which -all runtests”会返回什么:

/Documents/another/path_to/runtests.m 

/Applications/MATLAB_R2018a.app/toolbox/matlab/testframework/unittest/core/runtests.m % Shadowed

我的测试脚本位于:

/Documents/path_to/test/Test1.m

【问题讨论】:

  • uk.mathworks.com/help/matlab/ref/… 文档提示第一个输入不是文件
  • 还要确保您不会遇到 char-array 与 String 的问题。 "Test1.m" 和 'Test1.m' 有所作为。在我们的系统(Windows,Matlab 2017b)中,我们使用运行测试来执行工作目录中的所有测试,但对于更大的测试运行,我们使用显式测试套件。对我来说,有点不清楚你想要什么。
  • 我不认为此错误消息来自 MATLAB 附带的 runtests 函数。 “which -all runtests”的输出是什么?
  • @AndyCampbell 哦,谢谢,有趣的是它实际上指向我的测试脚本所在的文件夹
  • 是的,阻碍的是这个“其他”运行测试。您需要将其从路径中删除,以从框架运行测试函数中获得您期望的行为

标签: matlab unit-testing


【解决方案1】:

而不是通过调用文件来运行测试,你必须run them by calling the class:

run(TestSuite.fromClass(?Test1))

只要确保 Test1.m 在路径上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 2014-09-02
    • 2015-05-22
    • 2016-02-03
    • 1970-01-01
    相关资源
    最近更新 更多