Developer Zone

MATLAB的高级软件开发

Passing the Test

上次我们看到新版本13 YAML输出可以提供更丰富的CI系统体验,因为诊断设置为标准的结构化格式,可以通过机器(CI系统)读取并更干净地呈现给人类(您)。

我没有提到的一件事是Tapplugin(还有其他几个插件) now also supports passing diagnostics! It's as easy as an additional Name/Value pair when creating the plugin:

进口matlab.unittest.TestRunner;进口matlab.unittest.plugins.tapplugin;进口matlab.unittest.plugins.ToFile;try套房=测试套件('单元测试');Runner = testrunner.withTextOutput(“冗长”,3);%添加TAP插件tapFile = fullfile(getenv('WORKSPACE'),'testResults.tap');runner.addplugin(tapplugin.producingversion13(tofile(tapfile)),...“包括经过诊断”,真的);结果= runner.run(套件)catche disp(getReport(e,'extended')); exit(1);结尾exit;

通过这种简单的更改,现在输出不仅包括失败资格的诊断,还包括通过资格的诊断。现在,所有这些信息现在都可以存储在您的Jenkins日志中。看一看:

有几件事要立即注意到。首先,我们可以看到我在这里放大的测试正在通过。我们怎么知道而不挖掘文本?颜色告诉我们,寻找绿色!

Second, we can actually see that some of these tests passed without any qualifications at all. Since we see no passing diagnostics, we can infer that there was no call to验证等式orassertTrue或任何东西。这是预期的吗?没有把握。在某些时候,测试不需要执行任何验证步骤,而正确执行代码是所有需要的验证,但是如果我是贝丁男子,我会敢打赌,大多数情况下,有一个适当的可以并且应该做的验证。这种观点使这些事情更加清楚。

Why might we want to include passing diagnostics? Usually we are most concerned with the test failures and we don't really need to provide any insight into passing qualifications? While this is definitely true, including the passing diagnostics may prove to be desirable in a number of ways:

诊断证明- Showing the passing diagnostics gives more information to the user, including even simply the test name. When called upon to prove the behavior of your software at any point in time (or any version of your SCM system), keeping a history of your test runs and如何他们通过了(而不是thatthey passed) may prove valuable.

Diagnostics to find root causes- Unfortunately, test suites aren't perfect. They are very good defenses against the introduction of bugs, but sometimes bugs can slip passed their fortifications. However, when that happens you can look back into previously passing results and possibly gain insight into why the test suite didn't catch the bug. For example, in this example the test passes theverifyempty呼叫,但是如果正确的行为要求空的大小为空1x0,这些诊断能够表明这实际上是0x0细胞阵列是出乎意料的,可以解释为什么测试未能捕获错误的引入。

Diagnostics as specification- 最后,包括通过诊断包括可以提供自记录的测试意图。如果您将测试诊断作为最后的输入参数进行验证,则尤其如此。测试作者可以在域的语言中提供有关测试的预期行为的更多背景,因此,与此类报告结合使用时可以用作规范。这是一个重要而经常被误解的观点。为了支持通过诊断的显示,金宝app在编写测试时,我们应该以不取决于测试是否通过还是失败的方式提供诊断。它应该简单地说明预期的行为。您可以在此示例中看到:

默认情况下,顶点单元格数为空。

is much better than:

默认情况下,顶点单元格数不是空的。

一个普遍的错误是假设这些描述仅适用于失败,而实际上它们适用于通过和失败条件。

What are the downsides of leveraging passing diagnostics? Really it boils down to performance and verbosity. Not everyone will want to wade through all the passing diagnostics to analyze the failures, and not everyone will want to incur the extra time/space performance overhead that will come with including them. What about you? Do you find you need to analyze in more depth what happens in passing tests?




与Matlab®R2016B一起出版

|
  • 打印
  • 发送电子邮件

Comments

要发表评论,请单击here登录您的数学帐户或创建一个新帐户。