File tree 7 files changed +152
-0
lines changed
java/com/baeldung/testng/utils
test/java/com/baeldung/testng
7 files changed +152
-0
lines changed Original file line number Diff line number Diff line change 61
61
<module >testing-libraries-2</module >
62
62
<module >testing-libraries-3</module >
63
63
<module >testng</module >
64
+ <module >testng-2</module >
64
65
<module >testng-command-line</module >
65
66
<module >xmlunit-2</module >
66
67
<module >zerocode</module >
Original file line number Diff line number Diff line change
1
+ ### Relevant articles
Original file line number Diff line number Diff line change
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 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
4
+ <modelVersion >4.0.0</modelVersion >
5
+ <parent >
6
+ <groupId >com.baeldung</groupId >
7
+ <artifactId >testing-modules</artifactId >
8
+ <version >1.0.0-SNAPSHOT</version >
9
+ </parent >
10
+
11
+ <artifactId >testng-2</artifactId >
12
+ <version >0.0.1-SNAPSHOT</version >
13
+ <name >testng-2</name >
14
+ <description >Demo project for Baeldung Spring Boot TestNG</description >
15
+ <url />
16
+ <licenses >
17
+ <license />
18
+ </licenses >
19
+ <developers >
20
+ <developer />
21
+ </developers >
22
+ <scm >
23
+ <connection />
24
+ <developerConnection />
25
+ <tag />
26
+ <url />
27
+ </scm >
28
+ <properties >
29
+ <java .version>17</java .version>
30
+ <testng .version>7.10.2</testng .version>
31
+ <slf4j .version>2.0.16</slf4j .version>
32
+ </properties >
33
+ <dependencies >
34
+ <dependency >
35
+ <groupId >org.testng</groupId >
36
+ <artifactId >testng</artifactId >
37
+ <version >${testng.version} </version >
38
+ <scope >test</scope >
39
+ </dependency >
40
+ <dependency >
41
+ <groupId >org.slf4j</groupId >
42
+ <artifactId >slf4j-api</artifactId >
43
+ <version >${slf4j.version} </version >
44
+ </dependency >
45
+ </dependencies >
46
+
47
+ <build >
48
+ <plugins >
49
+ </plugins >
50
+ </build >
51
+ </project >
Original file line number Diff line number Diff line change
1
+ package com .baeldung .testng .utils ;
2
+
3
+ public class Counter {
4
+ private int totalCount ;
5
+
6
+ public Counter (int totalCount ) {
7
+ this .totalCount = totalCount ;
8
+ }
9
+
10
+ public int getTotalCount () {
11
+ return totalCount ;
12
+ }
13
+
14
+ public void addCounter (int number ) {
15
+ this .totalCount = totalCount + number ;
16
+ }
17
+
18
+ public void subtractCounter (int number ) {
19
+ this .totalCount = totalCount - number ;
20
+ }
21
+
22
+ public void resetTotalCount () {
23
+ this .totalCount = 0 ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ spring.application.name =testng-2
Original file line number Diff line number Diff line change
1
+ package com .baeldung .testng ;
2
+
3
+ import com .baeldung .testng .utils .Counter ;
4
+ import org .testng .annotations .BeforeMethod ;
5
+ import org .testng .annotations .BeforeTest ;
6
+ import org .testng .annotations .Test ;
7
+ import org .slf4j .Logger ;
8
+ import org .slf4j .LoggerFactory ;
9
+
10
+ public class BeforeMethodAnnotationTest {
11
+ private static final Logger log = LoggerFactory .getLogger (BeforeMethodAnnotationTest .class );
12
+
13
+ Counter counter ;
14
+
15
+ @ BeforeTest
16
+ public void init () {
17
+ log .info ("Initializing ..." );
18
+ counter = new Counter (0 );
19
+ }
20
+
21
+ @ BeforeMethod
22
+ public void givenCounterInitialized_whenResetTotalCount_thenTotalCountValueReset () {
23
+ log .info ("resetting total counter value ..." );
24
+ counter .resetTotalCount ();
25
+ }
26
+
27
+ @ Test
28
+ public void givenCounterInitialized_whenAddingValue_thenTotalCountIncreased () {
29
+ log .info ("total counter before added: {}" , counter .getTotalCount ());
30
+ counter .addCounter (2 );
31
+ log .info ("total counter after added: {}" , counter .getTotalCount ());
32
+ }
33
+
34
+ @ Test
35
+ public void givenCounterInitialized_whenSubtractingValue_thenTotalCountDecreased () {
36
+ log .info ("total counter before subtracted: {}" , counter .getTotalCount ());
37
+ counter .subtractCounter (2 );
38
+ log .info ("total counter after subtracted: {}" , counter .getTotalCount ());
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ package com .baeldung .testng ;
2
+
3
+ import com .baeldung .testng .utils .Counter ;
4
+ import org .testng .annotations .BeforeTest ;
5
+ import org .testng .annotations .Test ;
6
+ import org .slf4j .Logger ;
7
+ import org .slf4j .LoggerFactory ;
8
+
9
+ public class BeforeTestAnnotationTest {
10
+ private static final Logger log = LoggerFactory .getLogger (BeforeTestAnnotationTest .class );
11
+
12
+ Counter counter ;
13
+
14
+ @ BeforeTest
15
+ public void init () {
16
+ log .info ("Initializing ..." );
17
+ counter = new Counter (0 );
18
+ }
19
+
20
+ @ Test
21
+ public void givenCounterInitialized_whenAddingValue_thenTotalCountIncreased () {
22
+ log .info ("total counter before added: {}" , counter .getTotalCount ());
23
+ counter .addCounter (2 );
24
+ log .info ("total counter after added: {}" , counter .getTotalCount ());
25
+ }
26
+
27
+ @ Test
28
+ public void givenCounterInitialized_whenSubtractingValue_TotalCountDecreased () {
29
+ log .info ("total counter before subtracted: {}" , counter .getTotalCount ());
30
+ counter .subtractCounter (1 );
31
+ log .info ("total counter after subtracted: {}" , counter .getTotalCount ());
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments