This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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];

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

    Stack Information:
    In C:\work\SolverTest.m (SolverTest.testBadRealSolution) at 19
Done SolverTest

Failure Summary:

     Name                            Failed  Incomplete  Reason(s)
     SolverTest/testBadRealSolution    X                 Failed by verification.

Analyze Results

The output tells you SolverTest/testBadRealSolution failed. From the Framework Diagnostic you see the following:

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

At this point, you must decide if the error is in quadraticSolver or in your value for expSolution.

Correct Error

Edit the value of expSolution in testBadRealSolution:

expSolution = [-1 -2];

Rerun Tests

Save SolverTest and rerun only the failed tests.

failedTests = quadTests([result1.Failed]);
result2 = run(failedTests)
Running SolverTest
Done SolverTest

result2 = 

  TestResult with properties:

          Name: 'SolverTest/testBadRealSolution'
        Passed: 1
        Failed: 0
    Incomplete: 0
      Duration: 0.0108
       Details: [1x1 struct]

   1 Passed, 0 Failed, 0 Incomplete.
   0.010813 seconds testing time.
Was this topic helpful?