matlab.unittest.TestResult.generateDOCXReport - Generate DOCX test report from test results - MATLAB (original) (raw)

Class: matlab.unittest.TestResult
Namespace: matlab.unittest

Generate DOCX test report from test results

Since R2022a

Syntax

Description

generateDOCXReport([results](#mw%5Fe3cb260b-1c35-489f-ba97-4fc1aa39d8bd%5Fsep%5Fmw%5Fa3ed40f3-f3a5-42f7-8456-368226d59280)) generates a test report from the test results in DOCX format and saves it to a temporary folder.

Use this method to generate a DOCX test report once the test run is complete and the test results are available.

example

generateDOCXReport([results](#mw%5Fe3cb260b-1c35-489f-ba97-4fc1aa39d8bd%5Fsep%5Fmw%5Fa3ed40f3-f3a5-42f7-8456-368226d59280),[filename](#mw%5F7be6b0da-a909-4fdc-b5fb-5d15c145fdad)) saves the report using the specified filename.

generateDOCXReport(___,[Name=Value](#namevaluepairarguments)) specifies options using one or more name-value arguments in addition to any of the input argument combinations in previous syntaxes. For example,generateDOCXReport(results,PageOrientation="landscape") generates a test report in landscape orientation.

example

Input Arguments

expand all

Test results, specified as amatlab.unittest.TestResult array.

Name of the test report file, specified as a string scalar or character vector ending in .docx. The value can be a path relative to the current folder or an absolute path.

Example: "myTestReport.docx"

Example: "C:\work\myTestReport.docx"

Name-Value Arguments

expand all

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: generateDOCXReport(results,PageOrientation="landscape") generates a test report in landscape orientation.

Report orientation, specified as "portrait" or"landscape". By default, the method generates a report in portrait orientation.

Title of the test report, specified as a string scalar or character vector. By default, the method uses "MATLABĀ® Test Report" as the title.

Example: Title="My Test Report"

Examples

expand all

Run a suite of tests and then generate a DOCX test report from the test results.

Create a function-based test sampleTest.m in your current folder. The file contains two tests that pass and one test that fails.

function tests = sampleTest tests = functiontests(localfunctions); end

function testA(testCase) % Test passes verifyEqual(testCase,2+3,5) end

function testB(testCase) % Test fails verifyGreaterThan(testCase,13,42) end

function testC(testCase) % Test passes verifySubstring(testCase,"Hello World!","llo") end

Run the tests in sampleTest.m.

results = runtests("sampleTest");

Running sampleTest .

Verification failed in sampleTest/testB. --------------------- Framework Diagnostic: --------------------- verifyGreaterThan failed. --> The value must be greater than the minimum value.
Actual Value: 13 Minimum Value (Exclusive): 42 ------------------ Stack Information: ------------------ In C:\work\sampleTest.m (testB) at 10

.. Done sampleTest


Failure Summary:

 Name              Failed  Incomplete  Reason(s)
===============================================================
 sampleTest/testB    X                 Failed by verification.

Generate a DOCX test report from the test results in a temporary folder. By default, the report has portrait orientation.

generateDOCXReport(results)

Generating test report. Please wait. Preparing content for the test report. Adding content to the test report. Writing test report to file. Test report has been saved to: C:\TEMP\tp1036101c_483e_406a_acce_1f38be5d7a4d.docx

Generate another report in landscape orientation, and save it as myTestReport.docx in your current folder.

generateDOCXReport(results,"myTestReport.docx",PageOrientation="landscape")

Generating test report. Please wait. Preparing content for the test report. Adding content to the test report. Writing test report to file. Test report has been saved to: C:\work\myTestReport.docx

Open the test report in your current folder.

open("myTestReport.docx")

Limitations

Tips

Version History

Introduced in R2022a

expand all

To modify the title of your test report, specify the Title name-value argument.