1
package org.apache.maven.surefire.its.misc;
3
* Licensed to the Apache Software Foundation (ASF) under one
4
* or more contributor license agreements. See the NOTICE file
5
* distributed with this work for additional information
6
* regarding copyright ownership. The ASF licenses this file
7
* to you under the Apache License, Version 2.0 (the
8
* "License"); you may not use this file except in compliance
9
* with the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing,
14
* software distributed under the License is distributed on an
15
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
* KIND, either express or implied. See the License for the
17
* specific language governing permissions and limitations
21
import org.apache.maven.surefire.its.IntegrationTestSuiteResults;
24
import java.util.ArrayList;
25
import java.util.List;
26
import java.util.Locale;
28
import junit.framework.Assert;
30
@SuppressWarnings( { "JavaDoc" } )
31
public class HelperAssertions
34
* assert that the reports in the specified testDir have the right summary statistics
36
public static void assertTestSuiteResults( int total, int errors, int failures, int skipped, File testDir )
38
IntegrationTestSuiteResults suite = parseTestResults( new File[]{ testDir } );
39
assertTestSuiteResults( total, errors, failures, skipped, suite );
42
public static void assertTestSuiteResults( int total, int errors, int failures, int skipped,
43
IntegrationTestSuiteResults actualSuite )
45
Assert.assertEquals( "wrong number of tests", total, actualSuite.getTotal() );
46
Assert.assertEquals( "wrong number of errors", errors, actualSuite.getErrors() );
47
Assert.assertEquals( "wrong number of failures", failures, actualSuite.getFailures() );
48
Assert.assertEquals( "wrong number of skipped", skipped, actualSuite.getSkipped() );
51
public static IntegrationTestSuiteResults parseTestResults( File testDir )
53
return parseTestResults( new File[]{ testDir } );
56
public static IntegrationTestSuiteResults parseTestResults( File[] testDirs )
58
List<ReportTestSuite> reports = extractReports( testDirs );
59
return parseReportList( reports );
63
* Converts a list of ReportTestSuites into an IntegrationTestSuiteResults object, suitable for summary assertions
65
public static IntegrationTestSuiteResults parseReportList( List<ReportTestSuite> reports )
67
Assert.assertTrue( "No reports!", reports.size() > 0 );
68
int total = 0, errors = 0, failures = 0, skipped = 0;
69
for ( int i = 0; i < reports.size(); i++ )
71
ReportTestSuite suite = (ReportTestSuite) reports.get( i );
72
total += suite.getNumberOfTests();
73
errors += suite.getNumberOfErrors();
74
failures += suite.getNumberOfFailures();
75
skipped += suite.getNumberOfSkipped();
77
return new IntegrationTestSuiteResults( total, errors, failures, skipped );
80
public static List<ReportTestSuite> extractReports( File[] testDirs )
82
List<File> reportsDirs = new ArrayList<File>();
83
for ( int i = 0; i < testDirs.length; i++ )
85
File testDir = testDirs[i];
86
File reportsDir = new File( testDir, "target/surefire-reports" );
87
Assert.assertTrue( "Reports directory is missing: " + reportsDir.getAbsolutePath(), reportsDir.exists() );
88
reportsDirs.add( reportsDir );
90
SurefireReportParser parser = new SurefireReportParser( reportsDirs, Locale.getDefault() );
91
List<ReportTestSuite> reports;
94
reports = parser.parseXMLReportFiles();
98
throw new RuntimeException( "Couldn't parse XML reports", e );