许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  Matlab构造HTML报告插件:生成结构化报表的方法

Matlab构造HTML报告插件:生成结构化报表的方法

阅读数 5
点赞 0
article_banner

在您的工作文件夹中创建一个名为 ScriptBasedTest.m 的新文件,其中包含以下测试脚本。该脚本包括两个失败且未完成的测试。

%% Test double class

expSolution = 'double';

actSolution = ones;

assert(isa(actSolution,expSolution))

%% Test single class

expSolution = 'single';

actSolution = ones('single');

assert(isa(actSolution,expSolution))

%% Test uint16 class

expSolution = 'uint16';

actSolution = ones('uint16');

assert(isa(actSolution,expSolution))

%% Test that fails

assert(false==true);

%% Another test that fails

assert(strcmp('correlation','causation'))

创建一个名为 ClassBasedTest.m 的文件,其中包含以下测试类。该类包含一个失败的测试,经过参数化后,该测试产生九个失败的测试。

classdef ClassBasedTest < matlab.unittest.TestCase

properties (ClassSetupParameter)

generator = {'twister','combRecursive','multFibonacci'};

end

properties (MethodSetupParameter)

seed = {0,123,4294967295};

end

properties (TestParameter)

dim1 = struct('small',1,'medium',2,'large',3);

dim2 = struct('small',2,'medium',3,'large',4);

dim3 = struct('small',3,'medium',4,'large',5);

type = {'single','double'};

end

methods (TestClassSetup)

function ClassSetup(testCase,generator)

orig = rng;

testCase.addTeardown(@rng,orig)

rng(0, generator)

end

end

methods (TestMethodSetup)

function MethodSetup(testCase,seed)

orig = rng;

testCase.addTeardown(@rng,orig)

rng(seed)

end

end

methods (Test, ParameterCombination='sequential')

function testSize(testCase,dim1,dim2,dim3)

testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3])

end

end

methods (Test, ParameterCombination='pairwise')

function testRepeatable(testCase,dim1,dim2,dim3)

state = rng;

firstRun = rand(dim1,dim2,dim3);

rng(state)

secondRun = rand(dim1,dim2,dim3);

testCase.verifyEqual(firstRun,secondRun);

end

end

methods (Test)

function testClass(testCase,dim1,dim2,type)

testCase.verifyClass(rand(dim1,dim2,type),type)

end

end

end

在命令提示符下,根据两个测试文件创建一个测试套件。

import matlab.unittest.TestRunner;

import matlab.unittest.TestSuite;

import matlab.unittest.plugins.TestReportPlugin;

suite = testsuite({'ScriptBasedTest','ClassBasedTest'})

suite =

1×284 Test array with properties:

Name

ProcedureName

TestClass

BaseFolder

Parameterization

SharedTestFixtures

Tags

Tests Include:

17 Unique Parameterizations, 0 Shared Test Fixture Classes, 0 Tags.

创建一个静默测试运行程序,从而不在命令行窗口输出任何信息。创建 TestReportPlugin,它在名为 myResults 的文件夹中生成 .html 格式的测试报告。

runner = TestRunner.withNoPlugins;

htmlFolder = 'myResults';

plugin = TestReportPlugin.producingHTML(htmlFolder);

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

runner.addPlugin(plugin);

result = runner.run(suite)

Generating report. Please wait.

Preparing content for the report.

Adding content to the report.

Writing report to file.

Report has been saved to: C:\work\myResults\index.html

result =

1×284 TestResult array with properties:

Name

Passed

Failed

Incomplete

Duration

Details

Totals:

282 Passed, 2 Failed, 2 Incomplete.

1.6712 seconds testing time.

通过点击保存的文件的名称,打开测试报告。在此示例中,文件名为 C:\work\myResults\index.html。


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空