Merge pull request #1277 from eugenp/sla-pr/1272-testng
BAEL-701 - TestNG advanced
This commit is contained in:
commit
36f79aa956
234
testng/pom.xml
234
testng/pom.xml
|
@ -1,115 +1,121 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
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">
|
||||||
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>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<groupId>com.baeldung</groupId>
|
||||||
<groupId>com.baeldung</groupId>
|
<artifactId>testng</artifactId>
|
||||||
<artifactId>testng</artifactId>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<packaging>jar</packaging>
|
||||||
<packaging>jar</packaging>
|
<name>testng</name>
|
||||||
<name>testng</name>
|
|
||||||
|
<dependencies>
|
||||||
<dependencies>
|
|
||||||
|
<!-- logging -->
|
||||||
<!-- logging -->
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.slf4j</groupId>
|
||||||
<groupId>org.slf4j</groupId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<version>${org.slf4j.version}</version>
|
||||||
<version>${org.slf4j.version}</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<version>${logback.version}</version>
|
||||||
<version>${logback.version}</version>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
<!-- test scoped -->
|
||||||
<!-- test scoped -->
|
|
||||||
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.testng</groupId>
|
||||||
<groupId>org.testng</groupId>
|
<artifactId>testng</artifactId>
|
||||||
<artifactId>testng</artifactId>
|
<version>${testng.version}</version>
|
||||||
<version>${testng.version}</version>
|
<scope>test</scope>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
|
||||||
|
</dependencies>
|
||||||
</dependencies>
|
|
||||||
|
<build>
|
||||||
<build>
|
<finalName>testng</finalName>
|
||||||
<finalName>testng</finalName>
|
<resources>
|
||||||
<resources>
|
<resource>
|
||||||
<resource>
|
<directory>src/main/resources</directory>
|
||||||
<directory>src/main/resources</directory>
|
<filtering>true</filtering>
|
||||||
<filtering>true</filtering>
|
</resource>
|
||||||
</resource>
|
</resources>
|
||||||
</resources>
|
<testResources>
|
||||||
<testResources>
|
<testResource>
|
||||||
<testResource>
|
<directory>src/main/resources</directory>
|
||||||
<directory>src/main/resources</directory>
|
<filtering>true</filtering>
|
||||||
<filtering>true</filtering>
|
</testResource>
|
||||||
</testResource>
|
</testResources>
|
||||||
</testResources>
|
|
||||||
|
<plugins>
|
||||||
<plugins>
|
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<configuration>
|
||||||
<configuration>
|
<source>1.8</source>
|
||||||
<source>1.8</source>
|
<target>1.8</target>
|
||||||
<target>1.8</target>
|
</configuration>
|
||||||
</configuration>
|
</plugin>
|
||||||
</plugin>
|
|
||||||
|
<plugin>
|
||||||
<plugin>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
<configuration>
|
||||||
<configuration>
|
<excludes>
|
||||||
<excludes>
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
<exclude>**/*IntegrationTest.java</exclude>
|
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
<exclude>**/*ManualTest.java</exclude>
|
||||||
<exclude>**/*ManualTest.java</exclude>
|
</excludes>
|
||||||
</excludes>
|
<suiteXmlFiles>
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
<suiteXmlFile>src\test\resources\parametrized_testng.xml</suiteXmlFile>
|
||||||
</configuration>
|
<suiteXmlFile>src\test\resources\test_group.xml</suiteXmlFile>
|
||||||
</plugin>
|
<suiteXmlFile>src\test\resources\test_setup.xml</suiteXmlFile>
|
||||||
|
<suiteXmlFile>src\test\resources\test_suite.xml</suiteXmlFile>
|
||||||
<plugin>
|
</suiteXmlFiles>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
<executions>
|
</configuration>
|
||||||
<execution>
|
</plugin>
|
||||||
<id>copy-dependencies</id>
|
|
||||||
<phase>prepare-package</phase>
|
<plugin>
|
||||||
<goals>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<goal>copy-dependencies</goal>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
</goals>
|
<executions>
|
||||||
<configuration>
|
<execution>
|
||||||
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
<id>copy-dependencies</id>
|
||||||
</configuration>
|
<phase>prepare-package</phase>
|
||||||
</execution>
|
<goals>
|
||||||
</executions>
|
<goal>copy-dependencies</goal>
|
||||||
</plugin>
|
</goals>
|
||||||
</plugins>
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/libs</outputDirectory>
|
||||||
</build>
|
</configuration>
|
||||||
|
</execution>
|
||||||
<properties>
|
</executions>
|
||||||
|
</plugin>
|
||||||
<!-- logging -->
|
</plugins>
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
</build>
|
||||||
|
|
||||||
<!-- testing -->
|
<properties>
|
||||||
<testng.version>6.10</testng.version>
|
|
||||||
|
<!-- logging -->
|
||||||
<!-- maven plugins -->
|
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
<logback.version>1.1.7</logback.version>
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
|
||||||
|
<!-- testing -->
|
||||||
</properties>
|
<testng.version>6.10</testng.version>
|
||||||
|
|
||||||
|
<!-- maven plugins -->
|
||||||
|
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||||
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
|
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,25 +1,25 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class DependentTests {
|
public class DependentTests {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DependentTests.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DependentTests.class);
|
||||||
|
|
||||||
private String email = "abc@qwe.com";
|
private String email = "abc@qwe.com";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEmail_ifValid_thenTrue() {
|
public void givenEmail_ifValid_thenTrue() {
|
||||||
boolean valid = email.contains("@");
|
boolean valid = email.contains("@");
|
||||||
Assert.assertEquals(valid, true);
|
Assert.assertEquals(valid, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = {"givenEmail_ifValid_thenTrue"})
|
@Test(dependsOnMethods = {"givenEmail_ifValid_thenTrue"})
|
||||||
public void givenValidEmail_whenLoggedIn_thenTrue() {
|
public void givenValidEmail_whenLoggedIn_thenTrue() {
|
||||||
LOGGER.info("Email {} valid >> logging in", email);
|
LOGGER.info("Email {} valid >> logging in", email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,77 +1,77 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class ParametrizedTests {
|
public class ParametrizedTests {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ParametrizedTests.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ParametrizedTests.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Parameters({"value", "isEven"})
|
@Parameters({"value", "isEven"})
|
||||||
public void givenNumberFromXML_ifEvenCheckOK_thenCorrect(int value, boolean isEven) {
|
public void givenNumberFromXML_ifEvenCheckOK_thenCorrect(int value, boolean isEven) {
|
||||||
Assert.assertEquals(isEven, value % 2 == 0);
|
Assert.assertEquals(isEven, value % 2 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "numbers")
|
@DataProvider(name = "numbers")
|
||||||
public static Object[][] evenNumbers() {
|
public static Object[][] evenNumbers() {
|
||||||
return new Object[][]{{1, false}, {2, true}, {4, true}};
|
return new Object[][]{{1, false}, {2, true}, {4, true}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "numbers")
|
@Test(dataProvider = "numbers")
|
||||||
public void givenNumberFromDataProvider_ifEvenCheckOK_thenCorrect(Integer number, boolean expected) {
|
public void givenNumberFromDataProvider_ifEvenCheckOK_thenCorrect(Integer number, boolean expected) {
|
||||||
Assert.assertEquals(expected, number % 2 == 0);
|
Assert.assertEquals(expected, number % 2 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "numbersObject")
|
@Test(dataProvider = "numbersObject")
|
||||||
public void givenNumberObjectFromDataProvider_ifEvenCheckOK_thenCorrect(EvenNumber number) {
|
public void givenNumberObjectFromDataProvider_ifEvenCheckOK_thenCorrect(EvenNumber number) {
|
||||||
Assert.assertEquals(number.isEven(), number.getValue() % 2 == 0);
|
Assert.assertEquals(number.isEven(), number.getValue() % 2 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "numbersObject")
|
@DataProvider(name = "numbersObject")
|
||||||
public Object[][] parameterProvider() {
|
public Object[][] parameterProvider() {
|
||||||
return new Object[][]{{new EvenNumber(1, false)}, {new EvenNumber(2, true)}, {new EvenNumber(4, true),}};
|
return new Object[][]{{new EvenNumber(1, false)}, {new EvenNumber(2, true)}, {new EvenNumber(4, true),}};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class EvenNumber {
|
class EvenNumber {
|
||||||
private int value;
|
private int value;
|
||||||
private boolean isEven;
|
private boolean isEven;
|
||||||
|
|
||||||
public EvenNumber(int number, boolean isEven) {
|
public EvenNumber(int number, boolean isEven) {
|
||||||
this.value = number;
|
this.value = number;
|
||||||
this.isEven = isEven;
|
this.isEven = isEven;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(int value) {
|
public void setValue(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEven() {
|
public boolean isEven() {
|
||||||
return isEven;
|
return isEven;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEven(boolean even) {
|
public void setEven(boolean even) {
|
||||||
isEven = even;
|
isEven = even;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EvenNumber{" +
|
return "EvenNumber{" +
|
||||||
"value=" + value +
|
"value=" + value +
|
||||||
", isEven=" + isEven +
|
", isEven=" + isEven +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class RegistrationTest {
|
public class RegistrationTest {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationTest.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledFromSuite_thanOK() {
|
public void whenCalledFromSuite_thanOK() {
|
||||||
LOGGER.info("Registration successful");
|
LOGGER.info("Registration successful");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class SignInTest {
|
public class SignInTest {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SignInTest.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(SignInTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCalledFromSuite_thanOK() {
|
public void whenCalledFromSuite_thanOK() {
|
||||||
LOGGER.info("SignIn successful");
|
LOGGER.info("SignIn successful");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,98 +1,98 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.TestNG;
|
import org.testng.TestNG;
|
||||||
import org.testng.annotations.*;
|
import org.testng.annotations.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SummationServiceTest extends TestNG {
|
public class SummationServiceTest extends TestNG {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DependentTests.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DependentTests.class);
|
||||||
|
|
||||||
private List<Integer> numbers;
|
private List<Integer> numbers;
|
||||||
|
|
||||||
private int testCount = 0;
|
private int testCount = 0;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
numbers = new ArrayList<>();
|
numbers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
numbers = null;
|
numbers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeSuite(groups = "regression")
|
@BeforeSuite(groups = "regression")
|
||||||
public void runBeforeRegressionSuite() {
|
public void runBeforeRegressionSuite() {
|
||||||
numbers = new ArrayList<>();
|
numbers = new ArrayList<>();
|
||||||
numbers.add(-11);
|
numbers.add(-11);
|
||||||
numbers.add(2);
|
numbers.add(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterSuite(groups = "regression")
|
@AfterSuite(groups = "regression")
|
||||||
public void runAfterRegressionSuite() {
|
public void runAfterRegressionSuite() {
|
||||||
numbers = null;
|
numbers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeGroups("negative_tests")
|
@BeforeGroups("negative_tests")
|
||||||
public void runBeforeEachNegativeGroup() {
|
public void runBeforeEachNegativeGroup() {
|
||||||
numbers.clear();
|
numbers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeGroups("regression")
|
@BeforeGroups("regression")
|
||||||
public void runBeforeEachRegressionGroup() {
|
public void runBeforeEachRegressionGroup() {
|
||||||
numbers.add(-11);
|
numbers.add(-11);
|
||||||
numbers.add(2);
|
numbers.add(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeGroups("positive_tests")
|
@BeforeGroups("positive_tests")
|
||||||
public void runBeforeEachPositiveGroup() {
|
public void runBeforeEachPositiveGroup() {
|
||||||
numbers.add(1);
|
numbers.add(1);
|
||||||
numbers.add(2);
|
numbers.add(2);
|
||||||
numbers.add(3);
|
numbers.add(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups("positive_tests,regression,negative_tests")
|
@AfterGroups("positive_tests,regression,negative_tests")
|
||||||
public void runAfterEachGroup() {
|
public void runAfterEachGroup() {
|
||||||
numbers.clear();
|
numbers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void runBeforeEachTest() {
|
public void runBeforeEachTest() {
|
||||||
testCount++;
|
testCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
public void runAfterEachTest() {
|
public void runAfterEachTest() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(groups = "positive_tests", enabled = false)
|
@Test(groups = "positive_tests", enabled = false)
|
||||||
public void givenNumbers_sumEquals_thenCorrect() {
|
public void givenNumbers_sumEquals_thenCorrect() {
|
||||||
int sum = numbers.stream().reduce(0, Integer::sum);
|
int sum = numbers.stream().reduce(0, Integer::sum);
|
||||||
Assert.assertEquals(sum, 6);
|
Assert.assertEquals(sum, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "negative_tests")
|
@Test(groups = "negative_tests")
|
||||||
public void givenEmptyList_sumEqualsZero_thenCorrect() {
|
public void givenEmptyList_sumEqualsZero_thenCorrect() {
|
||||||
int sum = numbers.stream().reduce(0, Integer::sum);
|
int sum = numbers.stream().reduce(0, Integer::sum);
|
||||||
Assert.assertEquals(0, sum);
|
Assert.assertEquals(0, sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "regression")
|
@Test(groups = "regression")
|
||||||
public void givenNegativeNumber_sumLessthanZero_thenCorrect() {
|
public void givenNegativeNumber_sumLessthanZero_thenCorrect() {
|
||||||
int sum = numbers.stream().reduce(0, Integer::sum);
|
int sum = numbers.stream().reduce(0, Integer::sum);
|
||||||
Assert.assertTrue(sum < 0);
|
Assert.assertTrue(sum < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = ArithmeticException.class)
|
@Test(expectedExceptions = ArithmeticException.class)
|
||||||
public void givenNumber_whenThrowsException_thenCorrect() {
|
public void givenNumber_whenThrowsException_thenCorrect() {
|
||||||
int i = 1 / 0;
|
int i = 1 / 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,44 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class TestGroup {
|
public class TestGroup {
|
||||||
|
|
||||||
@BeforeGroups("database")
|
@BeforeGroups("database")
|
||||||
public void setupDB() {
|
public void setupDB() {
|
||||||
System.out.println("setupDB()");
|
System.out.println("setupDB()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups("database")
|
@AfterGroups("database")
|
||||||
public void cleanDB() {
|
public void cleanDB() {
|
||||||
System.out.println("cleanDB()");
|
System.out.println("cleanDB()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups= "selenium-test")
|
@Test(groups = "selenium-test")
|
||||||
public void runSelenium() {
|
public void runSelenium() {
|
||||||
System.out.println("runSelenium()");
|
System.out.println("runSelenium()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups= "selenium-test")
|
@Test(groups = "selenium-test")
|
||||||
public void runSelenium1() {
|
public void runSelenium1() {
|
||||||
System.out.println("runSelenium()1");
|
System.out.println("runSelenium()1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "database")
|
@Test(groups = "database")
|
||||||
public void testConnectOracle() {
|
public void testConnectOracle() {
|
||||||
System.out.println("testConnectOracle()");
|
System.out.println("testConnectOracle()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "database")
|
@Test(groups = "database")
|
||||||
public void testConnectMsSQL() {
|
public void testConnectMsSQL() {
|
||||||
System.out.println("testConnectMsSQL");
|
System.out.println("testConnectMsSQL");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnGroups = {"database","selenium-test"})
|
@Test(dependsOnGroups = {"database", "selenium-test"})
|
||||||
public void runFinal() {
|
public void runFinal() {
|
||||||
System.out.println("runFinal");
|
System.out.println("runFinal");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package baeldung.com;
|
package baeldung.com;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
public class TimeOutTest {
|
public class TimeOutTest {
|
||||||
|
|
||||||
@Test(timeOut = 1000, enabled = false)
|
@Test(timeOut = 1000, enabled = false)
|
||||||
public void givenExecution_takeMoreTime_thenFail() {
|
public void givenExecution_takeMoreTime_thenFail() {
|
||||||
while (true) ;
|
while (true) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,14 +1,14 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
|
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
|
||||||
</pattern>
|
</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
|
@ -1,10 +1,13 @@
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="My test suite">
|
<suite name="My test suite">
|
||||||
<test name="numbersXML">
|
<listeners>
|
||||||
<parameter name="value" value="1"/>
|
<listener class-name="com.baeldung.reports.CustomisedListener"></listener>
|
||||||
<parameter name="isEven" value="false"/>
|
</listeners>
|
||||||
<classes>
|
<test name="numbersXML">
|
||||||
<class name="baeldung.com.ParametrizedTests"/>
|
<parameter name="value" value="1"/>
|
||||||
</classes>
|
<parameter name="isEven" value="false"/>
|
||||||
</test>
|
<classes>
|
||||||
|
<class name="baeldung.com.ParametrizedTests"/>
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
</suite>
|
</suite>
|
|
@ -1,13 +1,13 @@
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="regression_test">
|
<suite name="regression_test">
|
||||||
<test name="test groups">
|
<test name="test groups">
|
||||||
<groups>
|
<groups>
|
||||||
<run>
|
<run>
|
||||||
<include name="regression"/>
|
<include name="regression"/>
|
||||||
</run>
|
</run>
|
||||||
</groups>
|
</groups>
|
||||||
<classes>
|
<classes>
|
||||||
<class name="baeldung.com.SummationServiceTest"/>
|
<class name="baeldung.com.SummationServiceTest"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
|
@ -1,17 +1,17 @@
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="regression_test">
|
<suite name="regression_test">
|
||||||
<test name="test setup">
|
<test name="test setup">
|
||||||
<groups>
|
<groups>
|
||||||
<run>
|
<run>
|
||||||
<include name="regression"/>
|
<include name="regression"/>
|
||||||
</run>
|
</run>
|
||||||
</groups>
|
</groups>
|
||||||
<classes>
|
<classes>
|
||||||
<class name="baeldung.com.SummationServiceTest">
|
<class name="baeldung.com.SummationServiceTest">
|
||||||
<methods>
|
<methods>
|
||||||
<include name="givenNumbers_sumEquals_thenCorrect"/>
|
<include name="givenNumbers_sumEquals_thenCorrect"/>
|
||||||
</methods>
|
</methods>
|
||||||
</class>
|
</class>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
|
@ -1,9 +1,12 @@
|
||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
<suite name="suite">
|
<suite name="suite" parallel="classes" thread-count="2">
|
||||||
<test name="test suite">
|
<listeners>
|
||||||
<classes>
|
<listener class-name="com.baeldung.reports.CustomisedReports" />
|
||||||
<class name="baeldung.com.RegistrationTest" />
|
</listeners>
|
||||||
<class name="baeldung.com.SignInTest" />
|
<test name="test suite">
|
||||||
</classes>
|
<classes>
|
||||||
</test>
|
<class name="baeldung.com.RegistrationTest" />
|
||||||
|
<class name="baeldung.com.SignInTest" />
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
</suite>
|
</suite>
|
Loading…
Reference in New Issue