From 17bfe63ea8974e0cb27281ef7d850178fcbf59a2 Mon Sep 17 00:00:00 2001 From: Ramon Caballero Date: Thu, 5 Sep 2024 16:15:54 +0100 Subject: [PATCH] Show excution order for Before and After annotations --- .gitignore | 10 +++++++ README.md | 8 ++++++ TestRunner.xml | 15 ++++++++++ src/tests/BaseTest.java | 62 +++++++++++++++++++++++++++++++++++++++++ src/tests/TestA.java | 25 +++++++++++++++++ src/tests/TestB.java | 25 +++++++++++++++++ 6 files changed, 145 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 TestRunner.xml create mode 100644 src/tests/BaseTest.java create mode 100644 src/tests/TestA.java create mode 100644 src/tests/TestB.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d93908 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Eclipse IDE settings files: +/.classpath +/.project +/.settings/ + +# Build generated folders: +/bin/ + +# TestNG generated folders: +test-output/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..1810522 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# TestNG + +Examples showing some TestNG features. + +## Run on Eclipse + +1. **Package Explorer** +2. Contextual menu on `TestRunner.xml` > **Run As** > **TestNG Suite** diff --git a/TestRunner.xml b/TestRunner.xml new file mode 100644 index 0000000..4f1e54b --- /dev/null +++ b/TestRunner.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/tests/BaseTest.java b/src/tests/BaseTest.java new file mode 100644 index 0000000..efaa76a --- /dev/null +++ b/src/tests/BaseTest.java @@ -0,0 +1,62 @@ +package tests; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; + +public abstract class BaseTest +{ + + @BeforeSuite + public void beforeSuite() + { + System.out.println("Before Suite"); + } + + @BeforeTest + public void beforeTest() + { + System.out.println("' Before Test"); + } + + @BeforeClass + public void beforeClass() + { + System.out.println("' ' Before Class"); + } + + @BeforeMethod + public void beforeMethod() + { + System.out.println("' ' ' Before Method"); + } + + @AfterMethod + public void afterMethod() + { + System.out.println("' ' ' After Method"); + } + + @AfterClass + public void afterClass() + { + System.out.println("' ' After Class"); + } + + @AfterTest + public void afterTest() + { + System.out.println("' After Test"); + } + + @AfterSuite + public void afterSuite() + { + System.out.println("After Suite"); + } +} diff --git a/src/tests/TestA.java b/src/tests/TestA.java new file mode 100644 index 0000000..a45b997 --- /dev/null +++ b/src/tests/TestA.java @@ -0,0 +1,25 @@ +package tests; + +import org.testng.annotations.Test; + +public class TestA extends BaseTest +{ + + @Test + public void testMethod01() + { + System.out.println("' ' ' ' TestA.testMethod01()"); + } + + @Test + public void testMethod02() + { + System.out.println("' ' ' ' TestA.testMethod02()"); + } + + @Test + public void testMethod03() + { + System.out.println("' ' ' ' TestA.testMethod03()"); + } +} diff --git a/src/tests/TestB.java b/src/tests/TestB.java new file mode 100644 index 0000000..bb5640d --- /dev/null +++ b/src/tests/TestB.java @@ -0,0 +1,25 @@ +package tests; + +import org.testng.annotations.Test; + +public class TestB extends BaseTest +{ + + @Test + public void testMethod01() + { + System.out.println("' ' ' ' TestB.testMethod01()"); + } + + @Test + public void testMethod02() + { + System.out.println("' ' ' ' TestB.testMethod02()"); + } + + @Test + public void testMethod03() + { + System.out.println("' ' ' ' TestB.testMethod03()"); + } +}