{"id":93641,"date":"2020-09-03T11:00:00","date_gmt":"2020-09-03T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=93641"},"modified":"2020-08-31T19:10:34","modified_gmt":"2020-08-31T16:10:34","slug":"testng-basic-annotations-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/","title":{"rendered":"TestNG Basic Annotations Tutorial"},"content":{"rendered":"<p>In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit.<\/p>\n<h2 class=\"wp-block-heading\">1. TestNG Annotations &#8211; Introduction<\/h2>\n<p>TestNG is a testing framework for the Java programming language created by Cedric Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities. The main features of TestNG include<\/p>\n<ul class=\"wp-block-list\">\n<li>Annotations.<\/li>\n<li>Run your tests in arbitrarily big thread pools with various policies available <\/li>\n<li>Test that your code is multithread safe.<\/li>\n<li>Flexible test configuration.<\/li>\n<li>Support for data-driven testing (with @DataProvider).<\/li>\n<li>Support for parameters.<\/li>\n<li>Powerful execution model.<\/li>\n<li>Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc&#8230;).<\/li>\n<li>Embeds Bean Shell for further flexibility.<\/li>\n<li>Default JDK functions for runtime and logging (no dependencies).<\/li>\n<li>Dependent methods for application server testing.<\/li>\n<\/ul>\n<p>In this post, we will deep dive into annotations and discover how it helps for testing workflows. Before that, we will look at the steps involved in creating a TestNG project. We will use Gradle as the build tool of choice. The section below discusses the build file<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml;highlight:[12,17,20]\">plugins {\n    id 'java'\n}\n\ngroup 'org.example'\nversion '1.0-SNAPSHOT'\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    testCompile group: 'org.testng', name: 'testng', version: '7.3.0'\n}\n\ntest {\n    useTestNG() {\n        useDefaultListeners = true\n    }\n    testLogging {\n        events \"PASSED\", \"FAILED\", \"SKIPPED\"\n    }\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>We have specified the repository for our dependencies as Maven central.<\/li>\n<li>In the dependencies section, we specify TestNG as the dependency.<\/li>\n<li>In the test task, we specify <code>useTestNG<\/code> to indicate the test task must use TestNG to run the tests.<\/li>\n<li>We also specify logging status for each test rather than the overall status.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">2. Test related annotations<\/h2>\n<p>We will cover three annotations in this section &#8211; <code>@Test<\/code>, <code>@BeforeClass<\/code> and <code>@AfterClass<\/code>. To illustrate the idea we will look at testing a simple calculator class.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Calculator.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">public class Calculator {\n\n    public int add(int a, int b){\n        return a+b;\n    }\n\n    public int subtract(int a, int b){\n        return a-b;\n    }\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>A simple class containing two operations &#8211; add and subtract<\/li>\n<\/ul>\n<p>To test this class we will define a test class which asserts the working of these functions<\/p>\n<p><span style=\"text-decoration: underline\"><em>CalculatorTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">import org.testng.Assert;\nimport org.testng.annotations.Test;\n\npublic class CalculatorTest {\n\n\n    @Test\n    public void addTest() {\n        Calculator calculator = new Calculator();\n        Assert.assertEquals(calculator.add(2,3),5);\n    }\n\n    @Test\n    public void subtractTest() {\n        Calculator calculator = new Calculator();\n        Assert.assertEquals(calculator.subtract(4,3),1);\n    }\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>We have specified <code>Test<\/code> annotation to indicate this is a test method<\/li>\n<li>We are using <code>Assert<\/code> to verify the expected result and actual result.<\/li>\n<\/ul>\n<p>The <code>@Test<\/code> annotation can be applied to the class level as well. When applied all public methods inside the class are executed as test cases. <\/p>\n<p> In the above example, we notice that we are initializing the Calculator class in every test. A better way to do that would be to use <code>@BeforeClass<\/code> annotation.<\/p>\n<p><span style=\"text-decoration: underline\"><em>CalculatorTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">import org.testng.Assert;\nimport org.testng.annotations.Test;\n\npublic class CalculatorTest {\nCalculator calculator;\n\n    @BeforeClass\n    public void setUp() {\n        calculator = new Calculator();\n    }\n\n...\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>We have initialized the <code>Calculator<\/code> class in <code>setUp<\/code> method which runs once before any of the test methods in the current class starts running.<\/li>\n<li>This ensures that we need not initialize the class during each test.<\/li>\n<\/ul>\n<p> Complementary of <code>@BeforeClass<\/code> is <code>@AfterClass<\/code>. This is generally used for closing the resources(IO) which are used in tests. For the above example, a scenario could be releasing the instance of <code>Calculator<\/code> class. This might not be necessary for our case with JVM doing the work but it is illustrated below to give the flavor.<\/p>\n<p><span style=\"text-decoration: underline\"><em>CalculatorTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">import org.testng.Assert;\nimport org.testng.annotations.Test;\n\npublic class CalculatorTest {\nCalculator calculator;\n\n     @BeforeClass\n    public void setUp() {\n        System.out.println(\"initialize calculator\");\n        calculator = new Calculator();\n    }\n\n    @AfterClass\n    public void tearDown() {\n        System.out.println(\"teardown calculator\");\n        calculator = null;\n    }\n\n...\n<\/pre>\n<p>Running this produces the following output<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:bash\">initialize calculator\nGradle suite &gt; Gradle test &gt; com.jcg.testng.CalculatorTest &gt; addTest PASSED\nGradle suite &gt; Gradle test &gt; com.jcg.testng.CalculatorTest &gt; subtractTest PASSED\nteardown calculator\n<\/pre>\n<p>In the above class, the class is initialized only once before any of the test is run. There might be cases where we want code to run for each test method. For this purpose there are annotations <code>@BeforeMethod<\/code> and <code>@AfterMethod<\/code>. <\/p>\n<p><span style=\"text-decoration: underline\"><em>CalculatorTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">import org.testng.Assert;\nimport org.testng.annotations.Test;\n\npublic class CalculatorTest {\nCalculator calculator;\n\n     @BeforeMethod\n    public void setUp() {\n        System.out.println(\"initialize calculator\");\n        calculator = new Calculator();\n    }\n\n    @AfterMethod\n    public void tearDown() {\n        System.out.println(\"teardown calculator\");\n        calculator = null;\n    }\n\n...\n<\/pre>\n<p>The output below indicates the execution of the methods before each test method is being called. <\/p>\n<pre class=\"brush:bash\">initialize calculator\nGradle suite &gt; Gradle test &gt; com.jcg.testng.CalculatorTest &gt; addTest PASSED\nteardown calculator\ninitialize calculator\nGradle suite &gt; Gradle test &gt; com.jcg.testng.CalculatorTest &gt; subtractTest PASSED\nteardown calculator\n<\/pre>\n<h2 class=\"wp-block-heading\">3. Test Group related annotations<\/h2>\n<p>In this section, we will explore annotations that will act when using a group of tests. We will start with <code>@BeforeSuite<\/code> and <code>@AfterSuite<\/code> annotations. A suite is represented by one XML file. It can contain one or more tests and is defined by the &lt;suite&gt; tag. <\/p>\n<p><span style=\"text-decoration: underline\"><em>testng.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;!DOCTYPE suite SYSTEM \"https:\/\/testng.org\/testng-1.0.dtd\" &gt;\n\n&lt;suite name=\"Suite1\" verbose=\"1\"&gt;\n    &lt;test name=\"add\"&gt;\n        &lt;classes&gt;\n            &lt;class name=\"com.jcg.testng.AddTest\"\/&gt;\n        &lt;\/classes&gt;\n    &lt;\/test&gt;\n\n    &lt;test name=\"subtract\"&gt;\n        &lt;classes&gt;\n            &lt;class name=\"com.jcg.testng.SubtractTest\"\/&gt;\n        &lt;\/classes&gt;\n    &lt;\/test&gt;\n&lt;\/suite&gt;\n<\/pre>\n<p>This is an XML suite file which contains a suite of two tests containing <code>AddTest<\/code> and <code>SubtractTest<\/code> which are just broken down from the <code>CalculatorTest<\/code> class.<\/p>\n<p>To execute something before the entire suite is executed i.e. initializing a heavy resource which would take time to initialize before each test class or method @<code>BeforeSuite<\/code> can be used.<\/p>\n<p><span style=\"text-decoration: underline\"><em>AddTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">...\n@BeforeSuite\n    public void setUpSuite() {\n        System.out.println(\"initialize before suite\");\n    }\n...\n@AfterSuite\n    public void tearDown() {\n        System.out.println(\"after suite\");\n    }\n<\/pre>\n<ul class=\"wp-block-list\">\n<li><code>BeforeSuite<\/code> can be present in any of the test classes<\/li>\n<li>It will be executed once before the entire suite is started<\/li>\n<li>It will be useful to initialize global variables which are needed by all executing tests(<a href=\"https:\/\/www.martinfowler.com\/bliki\/ObjectMother.html\">ObjectMother<\/a> pattern)<\/li>\n<\/ul>\n<pre class=\"brush:bash;\">initialize before suite\ninitialize calculator\ninitialize calculator\nafter suite\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>It first executes the <code>BeforeSuite<\/code> method<\/li>\n<li>It executes the two <code>BeforeClass<\/code> methods located in each test class<\/li>\n<li>Finally, it executes the <code>AfterSuite<\/code> method<\/li>\n<\/ul>\n<p>We will explore one more grouping other than the suite. It is the basic grouping of a test. A test need not be condensed into a single test method or class. Test here refers to a group of test cases logically grouped to verify a particular behavior while a suite consists of many tests. The hierarchy in TestNG is <strong>Suite &gt; Test &gt; Test Class &gt; Test Method<\/strong>. <\/p>\n<p>To illustrate this scenario lets add another test to our application for the functionality multiply.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Calculator.java<\/em><\/span><\/p>\n<pre class=\"brush:java\"> public int multiply(int a, int b) {\n        return a * b;\n    }\n<\/pre>\n<p>This is a simple function created to multiply two numbers as part of the calculator functionality. To assert this, we are creating another Test class.<\/p>\n<p><span style=\"text-decoration: underline\"><em>MultiplyTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">...\npublic class MultiplyTest {\n\n    Calculator calculator;\n\n    @BeforeClass\n    public void setUp() {\n        System.out.println(\"initialize calculator\");\n        calculator = new Calculator();\n    }\n\n    @BeforeTest\n    public void beforeTest() {\n        System.out.println(\"Before Test\");\n    }\n\n    @Test\n    public void multiplyTest() {\n        Assert.assertEquals(calculator.multiply(4, 3), 12);\n    }\n\n    @AfterTest\n    public void afterTest() {\n        System.out.println(\"After Test\");\n    }\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>This class is very similar to above tests.<\/li>\n<li>We have added <code>BeforeTest<\/code> and <code>AfterTest<\/code> annotations to ensure these get executed before any test method runs in the test group. <\/li>\n<li>To create a test group, refer the below testng.xml<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>testng.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;!DOCTYPE suite SYSTEM \"https:\/\/testng.org\/testng-1.0.dtd\" &gt;\n\n&lt;suite name=\"Suite1\" verbose=\"1\"&gt;\n    &lt;test name=\"addmul\"&gt;\n        &lt;classes&gt;\n            &lt;class name=\"com.jcg.testng.AddTest\"\/&gt;\n            &lt;class name=\"com.jcg.testng.MultiplyTest\"\/&gt;\n        &lt;\/classes&gt;\n    &lt;\/test&gt;\n\n    &lt;test name=\"subtract\"&gt;\n        &lt;classes&gt;\n            &lt;class name=\"com.jcg.testng.SubtractTest\"\/&gt;\n        &lt;\/classes&gt;\n    &lt;\/test&gt;\n&lt;\/suite&gt;\n<\/pre>\n<p>Here, We have added the <code>MultiplyTest<\/code> as part of the test containing <code>AddTest<\/code>. Now running the testng.xml produces the following result<\/p>\n<pre class=\"brush:bash\">initialize before suite\nBefore Test\ninitialize calculator\ninitialize calculator\nAfter Test\ninitialize calculator\nafter suite\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>We can see the <code>BeforeSuite<\/code> runs first followed by before test<\/li>\n<li>Then <code>BeforeClass<\/code> runs once for each test class<\/li>\n<li>This is followed by the <code>AfterTest<\/code><\/li>\n<li>The before class runs as part of the <code>SubtractTest<\/code> class<\/li>\n<li>Finally, the <code>AfterSuite<\/code> the method runs printing the message to console<\/li>\n<\/ul>\n<p>The last aspect we are going to look at is annotations catering to a group of tests. Let&#8217;s look at changing <code>CalculatorTest<\/code> to include groups.<\/p>\n<p><span style=\"text-decoration: underline\"><em>CalculatorTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\"> @BeforeGroups({\"addgrp\"})\n    public void beforeGroup() {\n        System.out.println(\"Before Group\");\n    }\n\n    @Test(groups = {\"addgrp\"})\n    public void addTest() {\n        Assert.assertEquals(calculator.add(2, 3), 5);\n    }\n\n    @Test(groups = {\"subgrp\"})\n    public void subtractTest() {\n        Assert.assertEquals(calculator.subtract(4, 3), 1);\n    }\n\n    @AfterGroups({\"addgrp\"})\n    public void afterGroup() {\n        System.out.println(\"After Group\");\n    }\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>We have added the <code>groups<\/code> attribute to test methods <code>addTest<\/code> and <code>subtractTest<\/code> to indicate the groups to which the test belongs<\/li>\n<li>The complements <code>BeforeGroups<\/code> and <code>AfterGroups<\/code> were added to demonstrate the behaviour<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>testng.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;test name=\"calc_add\"&gt;\n        &lt;groups&gt;\n            &lt;run&gt;\n                &lt;include name=\"addgrp\"\/&gt;\n            &lt;\/run&gt;\n        &lt;\/groups&gt;\n        &lt;classes&gt;\n            &lt;class name=\"com.jcg.testng.CalculatorTest\"\/&gt;\n        &lt;\/classes&gt;\n    &lt;\/test&gt;\n\n    &lt;test name=\"calc_sub\"&gt;\n        &lt;groups&gt;\n            &lt;run&gt;\n                &lt;include name=\"subgrp\"\/&gt;\n            &lt;\/run&gt;\n        &lt;\/groups&gt;\n        &lt;classes&gt;\n            &lt;class name=\"com.jcg.testng.CalculatorTest\"\/&gt;\n        &lt;\/classes&gt;\n    &lt;\/test&gt;\n<\/pre>\n<p>In the class definition, we just indicated the group for each test method. In the XML, we specify the groups for each <code>test<\/code>. We declare two additional tests within the same suite but under each test associate a specific group. We need to specify the classes associated with the test but also specify the group we want to include. <code>groups<\/code> also has the option of <code>exclude<\/code> using which we can exclude tests belonging to a group. Running this produces the following output<\/p>\n<pre class=\"brush:bash\">initialize before suite\nBefore Test\ninitialize calculator\nAfter Test\ninitialize calculator\nBefore Group\nAfter Group\nafter suite\n<\/pre>\n<h2 class=\"wp-block-heading\">4. Annotation Attributes <\/h2>\n<p>In the previous section, we covered the basic annotations available as part of TestNG. We covered a few attributes available as part of the annotations. This section is about the attributes available for the annotations. <\/p>\n<ul class=\"wp-block-list\">\n<li>alwaysRun &#8211; Applicable for all except BeforeGroups. When it is set to true, it will run irrespective of any failures.<\/li>\n<li>dependsOnGroups &#8211; This is used to indicate the test groups on which the annotated method depends on. If there is a failure in the group, this method is skipped. <\/li>\n<li>dependsOnMethods &#8211; Very similar to above except here it provides flexibility to specify methods than groups<\/li>\n<li>enabled &#8211; provides the capability to flexibility enable or disable annotated methods or classes<\/li>\n<li>inheritGroups &#8211; This annotation indicates that annotated method should inherit the groups from the test class <\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>CalculatorAttributeTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;\">@Test\npublic class CalculatorAttributeTest {\n\n    Calculator calculator = new Calculator();\n\n\n    @Test\n    public void addTest() {\n        Assert.assertEquals(calculator.add(4, 3), 6);\n    }\n\n    @Test(dependsOnMethods = {\"addTest\"})\n    public void subtractTest() {\n        Assert.assertEquals(calculator.subtract(4, 3), 1);\n    }\n\n    @Test(enabled = false)\n    public void multiplyTest() {\n        Assert.assertEquals(calculator.multiply(4, 3), 12);\n    }\n\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Running the above as it displays the output 1 skipped and 1 failed. subtractTest method never runs as addTest method fails<\/li>\n<li>Now adding the attribute alwaysRun with the value true to subtractTest the method ensures that it is run even if <code>addTest<\/code> fails.<\/li>\n<li>Now <code>multiplyTest<\/code> can be enabled by setting the <code>enabled<\/code> attribute to true or by removing the attribute itself. <\/li>\n<li>The changes above result in 2 successful tests and 1 failing test.<\/li>\n<\/ul>\n<p>The example has been illustrated with only the <code>Test<\/code> annotation but it is very similar for other annotations.<\/p>\n<h2 class=\"wp-block-heading\">5. Download the Source code<\/h2>\n<p>That was a TestNG Basic Annotations Tutorial.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/testng-3\/\"><strong>TestNG Basic Annotations Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations &#8211; Introduction TestNG is a testing framework for the Java programming language created by Cedric Beust and inspired by JUnit and NUnit. The design goal of TestNG is to &hellip;<\/p>\n","protected":false},"author":148,"featured_media":19768,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[901],"tags":[478,753],"class_list":["post-93641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-testng","tag-java","tag-testng"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>TestNG Basic Annotations Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations - Introduction\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TestNG Basic Annotations Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations - Introduction\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-03T08:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rajagopal ParthaSarathi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@PS_Rajagopal\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rajagopal ParthaSarathi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\"},\"author\":{\"name\":\"Rajagopal ParthaSarathi\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85\"},\"headline\":\"TestNG Basic Annotations Tutorial\",\"datePublished\":\"2020-09-03T08:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\"},\"wordCount\":1289,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg\",\"keywords\":[\"Java\",\"TestNG\"],\"articleSection\":[\"TestNG\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\",\"name\":\"TestNG Basic Annotations Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg\",\"datePublished\":\"2020-09-03T08:00:00+00:00\",\"description\":\"In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations - Introduction\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"TestNG\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/testng\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"TestNG Basic Annotations Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85\",\"name\":\"Rajagopal ParthaSarathi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g\",\"caption\":\"Rajagopal ParthaSarathi\"},\"description\":\"Rajagopal works in software industry solving enterprise-scale problems for customers across geographies specializing in distributed platforms. He holds a masters in computer science with focus on cloud computing from Illinois Institute of Technology. His current interests include data science and distributed computing.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/rajagopalparthasarathi\/\",\"https:\/\/x.com\/PS_Rajagopal\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/rajagopal-parthasarathi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TestNG Basic Annotations Tutorial - Java Code Geeks","description":"In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations - Introduction","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"TestNG Basic Annotations Tutorial - Java Code Geeks","og_description":"In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations - Introduction","og_url":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-09-03T08:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg","type":"image\/jpeg"}],"author":"Rajagopal ParthaSarathi","twitter_card":"summary_large_image","twitter_creator":"@PS_Rajagopal","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rajagopal ParthaSarathi","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/"},"author":{"name":"Rajagopal ParthaSarathi","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85"},"headline":"TestNG Basic Annotations Tutorial","datePublished":"2020-09-03T08:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/"},"wordCount":1289,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg","keywords":["Java","TestNG"],"articleSection":["TestNG"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/","name":"TestNG Basic Annotations Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg","datePublished":"2020-09-03T08:00:00+00:00","description":"In this post, we will take a look at TestNG annotations and how we can use them in unit tests for maximum benefit. 1. TestNG Annotations - Introduction","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/testng-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/testng-basic-annotations-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"TestNG","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/testng\/"},{"@type":"ListItem","position":5,"name":"TestNG Basic Annotations Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/c3c29bebb942f4a63a6a2d4c38411b85","name":"Rajagopal ParthaSarathi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cfb94a81445054c9121aae84e08c1e89caaae406739df92517996b0e41492b48?s=96&d=mm&r=g","caption":"Rajagopal ParthaSarathi"},"description":"Rajagopal works in software industry solving enterprise-scale problems for customers across geographies specializing in distributed platforms. He holds a masters in computer science with focus on cloud computing from Illinois Institute of Technology. His current interests include data science and distributed computing.","sameAs":["https:\/\/www.linkedin.com\/in\/rajagopalparthasarathi\/","https:\/\/x.com\/PS_Rajagopal"],"url":"https:\/\/examples.javacodegeeks.com\/author\/rajagopal-parthasarathi\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/93641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/148"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=93641"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/93641\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/19768"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=93641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=93641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=93641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}