What's the difference between failure and error in JUnit?

后端 未结 8 2503
粉色の甜心
粉色の甜心 2020-11-30 06:27

I\'m running JUnit tests on a large code base, and I\'ve been realizing that sometimes I get \"Errors\" while other times I get \"Failures\". What\'s the difference?

8条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 06:50

    Source class : JUnitReportReporter.java

    public void generateReport(List xmlSuites, List suites, String defaultOutputDirectory) {
    //......
    
                for (ITestResult tr : (Set) entry.getValue()) {
                    TestTag testTag = new TestTag();
    
                    boolean isSuccess = tr.getStatus() == 1;
                    if (!(isSuccess)) {
                        if (tr.getThrowable() instanceof AssertionError)
                            ++errors;
                        else {
                            ++failures;
                        }
                    }
    }
    

    As you can see below line in above method

    tr.getThrowable() instanceof AssertionError

    errors count is increased when it is instance of AssertionError otherwise(any Throwable) is counted as failures.

提交回复
热议问题