Skip to content

Commit d1f0b2e

Browse files
committed
BAEL-701 Introduction to TestNG
1 parent 99c8ee5 commit d1f0b2e

16 files changed

Lines changed: 597 additions & 454 deletions

‎testng/pom.xml‎

Lines changed: 120 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,121 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
6-
<groupId>com.baeldung</groupId>
7-
<artifactId>testng</artifactId>
8-
<version>0.1.0-SNAPSHOT</version>
9-
<packaging>jar</packaging>
10-
<name>testng</name>
11-
12-
<dependencies>
13-
14-
<!-- logging -->
15-
16-
<dependency>
17-
<groupId>org.slf4j</groupId>
18-
<artifactId>slf4j-api</artifactId>
19-
<version>${org.slf4j.version}</version>
20-
</dependency>
21-
<dependency>
22-
<groupId>ch.qos.logback</groupId>
23-
<artifactId>logback-classic</artifactId>
24-
<version>${logback.version}</version>
25-
</dependency>
26-
27-
<!-- test scoped -->
28-
29-
<dependency>
30-
<groupId>org.testng</groupId>
31-
<artifactId>testng</artifactId>
32-
<version>${testng.version}</version>
33-
<scope>test</scope>
34-
</dependency>
35-
36-
</dependencies>
37-
38-
<build>
39-
<finalName>testng</finalName>
40-
<resources>
41-
<resource>
42-
<directory>src/main/resources</directory>
43-
<filtering>true</filtering>
44-
</resource>
45-
</resources>
46-
<testResources>
47-
<testResource>
48-
<directory>src/main/resources</directory>
49-
<filtering>true</filtering>
50-
</testResource>
51-
</testResources>
52-
53-
<plugins>
54-
55-
<plugin>
56-
<groupId>org.apache.maven.plugins</groupId>
57-
<artifactId>maven-compiler-plugin</artifactId>
58-
<version>${maven-compiler-plugin.version}</version>
59-
<configuration>
60-
<source>1.8</source>
61-
<target>1.8</target>
62-
</configuration>
63-
</plugin>
64-
65-
<plugin>
66-
<groupId>org.apache.maven.plugins</groupId>
67-
<artifactId>maven-surefire-plugin</artifactId>
68-
<version>${maven-surefire-plugin.version}</version>
69-
<configuration>
70-
<excludes>
71-
<exclude>**/*IntegrationTest.java</exclude>
72-
<exclude>**/*LongRunningUnitTest.java</exclude>
73-
<exclude>**/*ManualTest.java</exclude>
74-
</excludes>
75-
<testFailureIgnore>true</testFailureIgnore>
76-
</configuration>
77-
</plugin>
78-
79-
<plugin>
80-
<groupId>org.apache.maven.plugins</groupId>
81-
<artifactId>maven-dependency-plugin</artifactId>
82-
<executions>
83-
<execution>
84-
<id>copy-dependencies</id>
85-
<phase>prepare-package</phase>
86-
<goals>
87-
<goal>copy-dependencies</goal>
88-
</goals>
89-
<configuration>
90-
<outputDirectory>${project.build.directory}/libs</outputDirectory>
91-
</configuration>
92-
</execution>
93-
</executions>
94-
</plugin>
95-
</plugins>
96-
97-
</build>
98-
99-
<properties>
100-
101-
<!-- logging -->
102-
<org.slf4j.version>1.7.21</org.slf4j.version>
103-
<logback.version>1.1.7</logback.version>
104-
105-
<!-- testing -->
106-
<testng.version>6.10</testng.version>
107-
108-
<!-- maven plugins -->
109-
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
110-
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
111-
112-
</properties>
113-
114-
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>testng</artifactId>
7+
<version>0.1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
<name>testng</name>
10+
11+
<dependencies>
12+
13+
<!-- logging -->
14+
15+
<dependency>
16+
<groupId>org.slf4j</groupId>
17+
<artifactId>slf4j-api</artifactId>
18+
<version>${org.slf4j.version}</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>ch.qos.logback</groupId>
22+
<artifactId>logback-classic</artifactId>
23+
<version>${logback.version}</version>
24+
</dependency>
25+
26+
<!-- test scoped -->
27+
28+
<dependency>
29+
<groupId>org.testng</groupId>
30+
<artifactId>testng</artifactId>
31+
<version>${testng.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
35+
</dependencies>
36+
37+
<build>
38+
<finalName>testng</finalName>
39+
<resources>
40+
<resource>
41+
<directory>src/main/resources</directory>
42+
<filtering>true</filtering>
43+
</resource>
44+
</resources>
45+
<testResources>
46+
<testResource>
47+
<directory>src/main/resources</directory>
48+
<filtering>true</filtering>
49+
</testResource>
50+
</testResources>
51+
52+
<plugins>
53+
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>${maven-compiler-plugin.version}</version>
58+
<configuration>
59+
<source>1.8</source>
60+
<target>1.8</target>
61+
</configuration>
62+
</plugin>
63+
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<version>${maven-surefire-plugin.version}</version>
68+
<configuration>
69+
<excludes>
70+
<exclude>**/*IntegrationTest.java</exclude>
71+
<exclude>**/*LongRunningUnitTest.java</exclude>
72+
<exclude>**/*ManualTest.java</exclude>
73+
</excludes>
74+
<suiteXmlFiles>
75+
<suiteXmlFile>src\test\resources\parametrized_testng.xml</suiteXmlFile>
76+
<suiteXmlFile>src\test\resources\test_group.xml</suiteXmlFile>
77+
<suiteXmlFile>src\test\resources\test_setup.xml</suiteXmlFile>
78+
<suiteXmlFile>src\test\resources\test_suite.xml</suiteXmlFile>
79+
</suiteXmlFiles>
80+
81+
<testFailureIgnore>true</testFailureIgnore>
82+
</configuration>
83+
</plugin>
84+
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-dependency-plugin</artifactId>
88+
<executions>
89+
<execution>
90+
<id>copy-dependencies</id>
91+
<phase>prepare-package</phase>
92+
<goals>
93+
<goal>copy-dependencies</goal>
94+
</goals>
95+
<configuration>
96+
<outputDirectory>${project.build.directory}/libs</outputDirectory>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
</plugins>
102+
103+
</build>
104+
105+
<properties>
106+
107+
<!-- logging -->
108+
<org.slf4j.version>1.7.21</org.slf4j.version>
109+
<logback.version>1.1.7</logback.version>
110+
111+
<!-- testing -->
112+
<testng.version>6.10</testng.version>
113+
114+
<!-- maven plugins -->
115+
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
116+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
117+
118+
</properties>
119+
120+
115121
</project>
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
package baeldung.com;
2-
3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
5-
import org.testng.Assert;
6-
import org.testng.annotations.Test;
7-
8-
public class DependentTests {
9-
10-
private static final Logger LOGGER = LoggerFactory.getLogger(DependentTests.class);
11-
12-
private String email = "abc@qwe.com";
13-
14-
@Test
15-
public void givenEmail_ifValid_thenTrue() {
16-
boolean valid = email.contains("@");
17-
Assert.assertEquals(valid, true);
18-
}
19-
20-
@Test(dependsOnMethods = {"givenEmail_ifValid_thenTrue"})
21-
public void givenValidEmail_whenLoggedIn_thenTrue() {
22-
LOGGER.info("Email {} valid >> logging in", email);
23-
}
24-
}
25-
1+
package baeldung.com;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.testng.Assert;
6+
import org.testng.annotations.Test;
7+
8+
public class DependentTests {
9+
10+
private static final Logger LOGGER = LoggerFactory.getLogger(DependentTests.class);
11+
12+
private String email = "abc@qwe.com";
13+
14+
@Test
15+
public void givenEmail_ifValid_thenTrue() {
16+
boolean valid = email.contains("@");
17+
Assert.assertEquals(valid, true);
18+
}
19+
20+
@Test(dependsOnMethods = {"givenEmail_ifValid_thenTrue"})
21+
public void givenValidEmail_whenLoggedIn_thenTrue() {
22+
LOGGER.info("Email {} valid >> logging in", email);
23+
}
24+
}
25+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package baeldung.com;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Test;
5+
6+
public class MultiThreadedTests {
7+
8+
@Test(threadPoolSize = 5, invocationCount = 10, timeOut = 1000)
9+
public void givenMethod_whenRunInThreads_thenCorrect(){
10+
int count = Thread.activeCount();
11+
Assert.assertTrue(count>1);
12+
}
13+
14+
}

0 commit comments

Comments
 (0)