MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Analyze Failed Test Results


This example shows how to identify and rerun failed tests.

Create an Incorrect Test Method

Using the SolverTest test case, add a method, testBadRealSolution. This test,
based on testRealSolution, calls the quadraticSolver function with inputs 1,3,2,
but tests the results against an incorrect solution, [2,1].

function testBadRealSolution(testCase)
actSolution = quadraticSolver(1,3,2);
expSolution = [2,1];
testCase.verifyEqual(actSolution,expSolution)
end

Run New Test Suite

Save the updated SolverTest class definition and rerun the tests.

quadTests = matlab.unittest.TestSuite.fromClass(?SolverTest);
result1 = run(quadTests);

Running SolverTest
..
================================================================================
Verification failed in SolverTest/testBadRealSolution.

---------------------
Framework Diagnostic:
---------------------
verifyEqual failed.
--> The values are not equal using "isequaln".
--> Failure table:
Index Actual Expected Error RelativeError
_____ ______ ________ _____ _____________

1 -1 2 -3 -1.5
2 -2 1 -3 -3

Actual Value:
-1 -2
Expected Value:
2 1

Analyze Failed Test Results
Free download pdf