Merge pull request #1277 from eugenp/sla-pr/1272-testng
BAEL-701 - TestNG advanced
This commit is contained in:
commit
36f79aa956
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
@ -72,6 +71,13 @@
|
|||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
</excludes>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>src\test\resources\parametrized_testng.xml</suiteXmlFile>
|
||||
<suiteXmlFile>src\test\resources\test_group.xml</suiteXmlFile>
|
||||
<suiteXmlFile>src\test\resources\test_setup.xml</suiteXmlFile>
|
||||
<suiteXmlFile>src\test\resources\test_suite.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package baeldung.com;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class MultiThreadedTests {
|
||||
|
||||
@Test(threadPoolSize = 5, invocationCount = 10, timeOut = 1000)
|
||||
public void givenMethod_whenRunInThreads_thenCorrect() {
|
||||
int count = Thread.activeCount();
|
||||
Assert.assertTrue(count > 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,12 +16,12 @@ public class TestGroup {
|
|||
System.out.println("cleanDB()");
|
||||
}
|
||||
|
||||
@Test(groups= "selenium-test")
|
||||
@Test(groups = "selenium-test")
|
||||
public void runSelenium() {
|
||||
System.out.println("runSelenium()");
|
||||
}
|
||||
|
||||
@Test(groups= "selenium-test")
|
||||
@Test(groups = "selenium-test")
|
||||
public void runSelenium1() {
|
||||
System.out.println("runSelenium()1");
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class TestGroup {
|
|||
System.out.println("testConnectMsSQL");
|
||||
}
|
||||
|
||||
@Test(dependsOnGroups = {"database","selenium-test"})
|
||||
@Test(dependsOnGroups = {"database", "selenium-test"})
|
||||
public void runFinal() {
|
||||
System.out.println("runFinal");
|
||||
}
|
||||
|
|
|
@ -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 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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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());
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
<suite name="My test suite">
|
||||
<listeners>
|
||||
<listener class-name="com.baeldung.reports.CustomisedListener"></listener>
|
||||
</listeners>
|
||||
<test name="numbersXML">
|
||||
<parameter name="value" value="1"/>
|
||||
<parameter name="isEven" value="false"/>
|
|
@ -1,5 +1,8 @@
|
|||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
<suite name="suite">
|
||||
<suite name="suite" parallel="classes" thread-count="2">
|
||||
<listeners>
|
||||
<listener class-name="com.baeldung.reports.CustomisedReports" />
|
||||
</listeners>
|
||||
<test name="test suite">
|
||||
<classes>
|
||||
<class name="baeldung.com.RegistrationTest" />
|
||||
|
|
Loading…
Reference in New Issue