フィルターのクリア

Logging the full results of a unit test in MATLAB unit test Framework

23 ビュー (過去 30 日間)
I am using the MATLAB unit test framework to test the output of my code. In my test bed, I noticed that, when I use the 'TestReporterPlugin' to output the test results to a PDF, the elements of vectors over 10 elements in length will not print out explicitly.
For example, the test method below outputs the entire vector. Note that this is a test method of a subclass of 'matlab.unittest.TestCase'.
function testExample(testCase)
expected = ones(1,10);
actual = ones(1,10);
testCase.verifyEqual(actual,expected)
end
The test report output from this method is shown below:
verifyEqual passed.
--> The values are equal using "isequaln".
Actual Value:
1 1 1 1 1 1 1 1 1 1
Expected Value:
1 1 1 1 1 1 1 1 1 1
However, if I change 'actual' and 'expected' to 'ones(1,11)', the elements of the output are suppressed, as shown below:
verifyEqual passed.
--> The values are equal using "isequaln".
Actual Value:
1x11 double
Expected Value:
1x11 double
Is there a way that I can output the entire vector to the Test Report?

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 4 月 17 日
編集済み: MathWorks Support Team 2024 年 4 月 17 日
There are several known workarounds to modify the method "testExample"
1. You can use 'DisplayDiagnostic' objects as 'test diagnostics', which occupy the last input of the qualification method. 
The code snippet below details this approach:
function testExample(testCase)
import matlab.unittest.diagnostics.DisplayDiagnostic
actual = ones(1,11);
expected = ones(1,11);
testCase.verifyEqual(actual,expected,[DisplayDiagnostic(expected) DisplayDiagnostic(actual)]);
end
More information about the 'DisplayDiagnostic' class can be found at the link below:
2. You can create a nested function to customize the display, and pass this in as a test diagnostic. The code snippet below illustrates this approach:
function testExample(testCase)
actual = ones(1,11);
expected = ones(1,11);
testCase.verifyEqual(actual,expected,@displayActExp);
function displayActExp()
disp('Actual:');
disp (actual);
disp ('Expected:');
disp (expected);
end
end
The documentation for 'Function Handle Diagnostics' is linked below:
Both of these elements will produce the desired output in the Test Report.
  1 件のコメント
Steven Lord
Steven Lord 2018 年 5 月 10 日
verifyThat will accept a diagnostic input argument, either as a char vector or as a function handle.
>> TC = matlab.unittest.TestCase.forInteractiveUse;
>> import matlab.unittest.constraints.IsEqualTo;
>> verifyThat(TC, 1+1, IsEqualTo(3), 'Why doesn''t 1+1 equal 3?')
Interactive verification failed.
----------------
Test Diagnostic:
----------------
Why doesn't 1+1 equal 3?
---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> NumericComparator failed.
--> The values are not equal using "isequaln".
--> Failure table:
Actual Expected Error RelativeError
______ ________ _____ __________________
2 3 -1 -0.333333333333333
Actual Value:
2
Expected Value:
3
The diagnostic message looks like it's the third input if you call it using dot notation, but it's actually the fourth.
TC.verifyThat(1+1, IsEqualTo(3), 'Why doesn''t 1+1 equal 3?')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction-Based Unit Tests についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by