BAEL-701 Introduction to TestNG
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.baeldung.reports;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.ITestListener;
|
||||
import org.testng.ITestResult;
|
||||
|
||||
public class CustomisedListener implements ITestListener {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("TEST_REPORT");
|
||||
|
||||
@Override
|
||||
public void onFinish(ITestContext arg0) {
|
||||
LOGGER.info("PASSED TEST CASES");
|
||||
arg0.getPassedTests()
|
||||
.getAllResults()
|
||||
.stream()
|
||||
.forEach(result -> {
|
||||
LOGGER.info(result.getName());
|
||||
});
|
||||
LOGGER.info("FAILED TEST CASES");
|
||||
arg0.getFailedTests()
|
||||
.getAllResults()
|
||||
.stream()
|
||||
.forEach(result -> {
|
||||
LOGGER.info(result.getName());
|
||||
});
|
||||
LOGGER.info("Test completed on: "+arg0.getEndDate().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(ITestContext arg0) {
|
||||
LOGGER.info("Started testing on: " + arg0.getStartDate()
|
||||
.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTestFailure(ITestResult arg0) {
|
||||
LOGGER.info("Failed : " + arg0.getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTestSkipped(ITestResult arg0) {
|
||||
LOGGER.info("Skipped Test: " + arg0.getName());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTestStart(ITestResult arg0) {
|
||||
LOGGER.info("Testing: " + arg0.getName() + " " + arg0.getStartMillis());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTestSuccess(ITestResult arg0) {
|
||||
LOGGER.info("Tested: " + arg0.getName() + " " + arg0.getEndMillis());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.baeldung.reports;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.IReporter;
|
||||
import org.testng.ISuite;
|
||||
import org.testng.ISuiteResult;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.xml.XmlSuite;
|
||||
|
||||
public class CustomisedReports implements IReporter {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("TEST_REPORT");
|
||||
|
||||
@Override
|
||||
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
|
||||
|
||||
suites.stream()
|
||||
.forEach(suite -> {
|
||||
String suiteName = suite.getName();
|
||||
Map<String, ISuiteResult> suiteResults = suite.getResults();
|
||||
suiteResults.values()
|
||||
.stream()
|
||||
.forEach(result -> {
|
||||
ITestContext context
|
||||
= ((ISuiteResult) result).getTestContext();
|
||||
|
||||
LOGGER.info("Passed tests for suite '"
|
||||
+ suiteName + "' is:"
|
||||
+ context.getPassedTests()
|
||||
.getAllResults()
|
||||
.size());
|
||||
LOGGER.info("Failed tests for suite '"
|
||||
+ suiteName + "' is:"
|
||||
+ context.getFailedTests()
|
||||
.getAllResults()
|
||||
.size());
|
||||
LOGGER.info("Skipped tests for suite '"
|
||||
+ suiteName + "' is:"
|
||||
+ context.getSkippedTests()
|
||||
.getAllResults()
|
||||
.size());
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user