matlab输出信息到屏幕,将文本信息显示到屏幕上的输出流

在您的工作文件夹中,创建包含以下测试类的文件 ExampleTest.m。

classdef ExampleTest < matlab.unittest.TestCase

methods(Test)

function testOne(testCase) % Test fails

testCase.verifyEqual(5, 4, 'Testing 5==4')

end

function testTwo(testCase) % Test passes

testCase.verifyEqual(5, 5, 'Testing 5==5')

end

function testThree(testCase)

% test code

end

end

end

testOne 中的 verifyEqual 验证导致测试失败。testOne 和 testTwo 中的验证包括 matlab.unittest.diagnostics.StringDiagnostic 实例。

在命令提示符下,基于 ExampleTest 类创建测试套件。

import matlab.unittest.TestRunner

import matlab.unittest.TestSuite

import matlab.unittest.plugins.DiagnosticsOutputPlugin

import matlab.unittest.plugins.ToStandardOutput

suite = TestSuite.fromClass(?ExampleTest);

创建一个不含任何插件的测试运行程序。此代码创建一个静默运行程序并向您提供对安装的插件的完整控制权。

runner = TestRunner.withNoPlugins;

创建一个 DiagnosticsOutputPlugin,它显式指定其输出应定向到屏幕。

plugin = DiagnosticsOutputPlugin(ToStandardOutput);

将该插接添加到 TestRunner 并运行套件。

runner.addPlugin(plugin)

result = runner.run(suite);

================================================================================

Verification failed in ExampleTest/testOne.

----------------

Test Diagnostic:

----------------

Testing 5==4

---------------------

Framework Diagnostic:

---------------------

verifyEqual failed.

--> The values are not equal using "isequaln".

--> Failure table:

Actual Expected Error RelativeError

______ ________ _____ _____________

5 4 1 0.25

Actual Value:

5

Expected Value:

4

------------------

Stack Information:

------------------

In C:\work\ExampleTest.m (ExampleTest.testOne) at 4

================================================================================

Failure Summary:

Name Failed Incomplete Reason(s)

==================================================================

ExampleTest/testOne X Failed by verification.

只有测试失败才在屏幕上产生输出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值