org.etlunit.feature.results.ResultsFeatureModule Maven / Gradle / Ivy
package org.etlunit.feature.results;
import org.etlunit.*;
import org.etlunit.feature.AbstractFeature;
import org.etlunit.feature.FeatureModule;
import org.etlunit.parser.ETLTestClass;
import org.etlunit.parser.ETLTestMethod;
import java.util.HashMap;
import java.util.Map;
@FeatureModule
public class ResultsFeatureModule extends AbstractFeature
{
private final Map classResultsMap = new HashMap();
private final Map methodResultsMap = new HashMap();
private TestResults testResults = null;
private final StatusReporter reporter = new ResultsReporter();
private long startTime;
private long runTime;
private final class ResultsReporter extends NullStatusReporterImpl
{
@Override
public void testsStarted(int numTestsSelected)
{
testResults = new TestResultsImpl(numTestsSelected);
classResultsMap.clear();
methodResultsMap.clear();
testResults.reset();
startTime = System.currentTimeMillis();
userLog.info("Processing [" + numTestsSelected + "] tests");
}
@Override
public void testsCompleted()
{
runTime = System.currentTimeMillis() - startTime;
TestResults results = getTestClassResults();
TestResultMetrics metrics = results.getMetrics();
userLog.info("Tests run: "
+ results.getNumTestsSelected()
+ ", Successes: "
+ metrics.getNumberOfTestsPassed()
+ ", Failures: "
+ metrics.getNumberOfAssertionFailures()
+ ", Errors: "
+ metrics.getNumberOfErrors()
+ ", Warnings: "
+ metrics.getNumberOfWarnings()
+ ", Time elapsed: "
+ (runTime / 1000.0)
+ " sec");
}
@Override
public void testCompleted(ETLTestMethod method, CompletionStatus status)
{
// update stats on the class
ETLTestClass testClass = method.getTestClass();
TestClassResultImpl clsrep = classResultsMap.get(testClass.getName());
if (clsrep == null)
{
clsrep = new TestClassResultImpl(testClass);
classResultsMap.put(testClass.getName(), clsrep);
testResults.getResultsByClass().add(clsrep);
}
String qualifiedName = testClass.getName() + "." + method.getName();
TestMethodResultImpl mthdrep = methodResultsMap.get(qualifiedName);
if (mthdrep == null)
{
mthdrep = new TestMethodResultImpl(testClass.getName(), method.getName());
methodResultsMap.put(qualifiedName, mthdrep);
clsrep.getMethodResults().add(mthdrep);
}
// add metrics for all levels
TestResultMetrics clsTestResults = clsrep.getMetrics();
TestResultMetrics mthdTestResults = mthdrep.getMetrics();
TestResultMetrics resultMetrics = testResults.getMetrics();
clsTestResults.addStatus(method, status);
mthdTestResults.addStatus(method, status);
resultMetrics.addStatus(method, status);
clsTestResults.addTestWarnings(status.getWarnings().size());
mthdTestResults.addTestWarnings(status.getWarnings().size());
resultMetrics.addTestWarnings(status.getWarnings().size());
switch (status.getTestResult())
{
case warning:
case success:
clsTestResults.addTestsPassed(1);
mthdTestResults.addTestsPassed(1);
resultMetrics.addTestsPassed(1);
break;
case failure:
clsTestResults.addAssertionFailures(status.getAssertionFailures().size());
mthdTestResults.addAssertionFailures(status.getAssertionFailures().size());
resultMetrics.addAssertionFailures(status.getAssertionFailures().size());
break;
case error:
clsTestResults.addErrors(1);
mthdTestResults.addErrors(1);
resultMetrics.addErrors(1);
break;
}
}
}
@Override
public StatusReporter getStatusReporter()
{
return reporter;
}
public TestResults getTestClassResults()
{
return testResults;
}
public String getFeatureName()
{
return "results";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy