<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ruchira Shukla</title>
    <description>The latest articles on DEV Community by Ruchira Shukla (@ruchirashukla).</description>
    <link>https://dev.to/ruchirashukla</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F898904%2F0588d2f2-3f68-46fe-adba-b545352156f1.png</url>
      <title>DEV Community: Ruchira Shukla</title>
      <link>https://dev.to/ruchirashukla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ruchirashukla"/>
    <language>en</language>
    <item>
      <title>How To Run JUnit Selenium Tests using TestNG</title>
      <dc:creator>Ruchira Shukla</dc:creator>
      <pubDate>Fri, 05 Aug 2022 09:49:23 +0000</pubDate>
      <link>https://dev.to/testmuai/how-to-run-junit-selenium-tests-using-testng-2dnl</link>
      <guid>https://dev.to/testmuai/how-to-run-junit-selenium-tests-using-testng-2dnl</guid>
      <description>&lt;p&gt;Both JUnit and TestNG are popular unit testing frameworks that have been widely accepted by Java developers. JUnit was introduced as an open-source unit testing framework for Java way back in 1997. In fact, JUnit is one of the widely used test automation frameworks for &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt;. TestNG is another Java-based test automation framework that is not only open-source but also offers awesome features that are best suited for large-scale web automation testing. TestNG was created for a range of testing categories, including (but not limited to) unit testing, functional testing, &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;end-to-end testing&lt;/a&gt;, and integration testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F529geap36tk8hx3xlnjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F529geap36tk8hx3xlnjq.png" width="380" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like me, if you are well-versed with both the test automation frameworks, you might come across scenarios where you would want to run JUnit tests using TestNG. The major push for this cross-pollination (to put it in simple terms) is the extensive set of features provided by the TestNG framework. TestNG supports broader categories of tests, making it easy for testers to migrate the JUnit test cases to the TestNG framework. The advantage of this approach is avoiding complete rewrite of the test scenarios that are using the JUnit framework.&lt;/p&gt;

&lt;p&gt;In this blog, we look at how you can run test cases using JUnit and &lt;a href="https://www.lambdatest.com/learning-hub/testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG in Selenium&lt;/a&gt; without any re-work in writing the tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey! Test on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Testing&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to JUnit
&lt;/h2&gt;

&lt;p&gt;Java came up with its open-source unit testing framework called JUnit, following the practice of extreme programming. Though JUnit is primarily used for unit testing, &lt;a href="https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated testing with JUnit and Selenium&lt;/a&gt; can be extensively used for cross browser testing (or browser compatibility testing).&lt;/p&gt;

&lt;p&gt;On the other hand, the TestNG (Test Next Generation) framework has advanced features that let you perform various categories of tests (i.e., unit testing, integration testing, functional testing, etc.).&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install JUnit
&lt;/h2&gt;

&lt;p&gt;The latest version of JUnit is JUnit 5. Unlike JUnit 4, JUnit 5 is composed of modules from three different projects — JUnit Platform, JUnit Jupiter, and JUnit Vintage.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JUnit Platform — Provides the base for launching testing frameworks&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JUnit Jupiter — Provides a TestEngine for running Jupiter-based tests on the platform&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JUnit Vintage — Provides a test engine for running Unit 3 and JUnit 4 tests&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In case you are using JUnit 4 tests and intrigued to know about running with the JUnit 5 framework, do have a look at our blog that helps you &lt;a href="https://www.lambdatest.com/blog/execute-junit4-tests-with-junit5/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;execute JUnit 4 tests with JUnit 5&lt;/a&gt; framework.&lt;/p&gt;

&lt;p&gt;To get started with the JUnit framework, follow the below-mentioned steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To install JUnit in your project, navigate to the &lt;a href="https://junit.org/junit5/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit 5&lt;/a&gt; website → Docs → User Guide and download the dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To use JUnit, include the jar files in your project ClassPath.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To use JUnit in Eclipse, include JUnit libraries in your Java project. For example, Right-click on the Java project → Properties → Java Build Path → Add Libraries → Select JUnit → Choose library version (JUnit 4/JUnit5).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check our &lt;a href="https://www.lambdatest.com/blog/setup-junit-environment/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;getting started with JUnit&lt;/a&gt; blog to take the first steps in using the framework for Selenium test automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create and execute test cases in JUnit
&lt;/h2&gt;

&lt;p&gt;JUnit provides a handful of annotations to create and execute test cases. Therefore, it is important to have a good understanding of &lt;a href="https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit Annotations in Selenium&lt;/a&gt; if you are using the framework for Selenium automation testing.&lt;/p&gt;

&lt;p&gt;Now that we have covered the essentials of JUnit, let’s get our hands dirty with a JUnit test example that demonstrates Selenium test automation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to &lt;a href="https://todomvc.com/examples/react/#/" rel="noopener noreferrer"&gt;https://todomvc.com/examples/react/#/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the text “JUnit Parallel Test sample” in the textbox&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the exact text appears in the list below the textbox&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To implement the above test case, we will write JUnitDemo test class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;

    public class JUnitDemo {
       WebDriver driver;

       @Before
       public void setUp() throws Exception {
           System.setProperty("webdriver.chrome.driver", "YOUR DRIVER EXE PATH");
           driver = new ChromeDriver();

       }

       @Test
       public void testJunitDemo() throws Exception {
           try { // Change it to production page
               int total_elements = 0;
               driver.get("https://todomvc.com/examples/react/#/");
               driver.findElement(By.className("new-todo")).sendKeys("JUnit Test sample");
               driver.findElement(By.className("new-todo")).sendKeys(Keys.ENTER);
               total_elements = driver.findElements(By.xpath("//ul[@class='todo-list']/li//label")).size();
               Assert.assertEquals(1, total_elements);

           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
       }

       @After
       public void tearDown() throws Exception {
           driver.quit();
       }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;@Before and @After annotations specify that the method code will be executed before and after each test method. An assert is not raised if the expected result matches the actual result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The test method testJUnitDemo contains the &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; script to perform the test steps. If you are using the JUnit framework, you should leverage &lt;a href="https://www.lambdatest.com/blog/junit-parameterized-test-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parameterized testing with JUnit&lt;/a&gt; to make the most out of Selenium and JUnit as a complete package!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to run JUnit Test
&lt;/h2&gt;

&lt;p&gt;1- To run the above code in Eclipse, right-click on the test class and select Run As → JUnit Test.&lt;/p&gt;

&lt;p&gt;2- To run the test case outside Eclipse, you can create a TestRunner class.&lt;/p&gt;

&lt;p&gt;3- You can include more than one test using runClasses testclass1,[testclass2,…].&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import org.junit.runner.JUnitCore;
    import org.junit.runner.Result;
    import org.junit.runner.notification.Failure;
    public class TestRunner {
      public static void main(String[] args) {
         Result result = JUnitCore.runClasses(JUnitDemo.class);
         for (Failure failure : result.getFailures()) {
            System.out.println(failure.toString());
         }
         System.out.println(result.wasSuccessful());
      }
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- To run in the command line, follow the syntax-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ java org.junit.runner.JUnitCore TestClass1 [TestClass2 ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can refer to our detailed &lt;a href="https://www.lambdatest.com/learning-hub/junit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit Tutorial&lt;/a&gt; on the LambdaTest learning hub to gain insights into the other offerings of the JUnit framework.&lt;/p&gt;

&lt;p&gt;Watch this video to learn how TestNG has become one of the most robust test automation frameworks and all you need to know to get started with TestNG in Selenium.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/90F7dePW1vo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to TestNG
&lt;/h2&gt;

&lt;p&gt;TestNG is also a very prevalent Java testing framework that is widely used by the developer and tester community. The framework is extensively used for test creation with an immense focus on features such as grouping, dependency, prioritization, annotations, and more. At the time of writing this blog, the latest version of TestNG is version 7.3.0.&lt;/p&gt;

&lt;p&gt;With TestNG certification, you can challenge your skills in performing automated testing with TestNG and take your career to the next level.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the TestNG certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dzXX2hJhuCY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automate &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt; and perform browser automation testing with LambdaTest Now!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install TestNG
&lt;/h2&gt;

&lt;p&gt;Head over to the official website of TestNG and copy the dependencies (Maven/Gradle) to your project. In case you are using the Eclipse IDE, you can refer to our comprehensive guide on how to &lt;a href="https://www.lambdatest.com/blog/how-to-install-testng-in-eclipse-step-by-step-guide/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;install TestNG in Eclipse&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you have installed Eclipse on your system, you have to create a project and download the corresponding dependencies. You can check out our blog to help you create a &lt;a href="https://www.lambdatest.com/blog/how-to-install-testng-in-eclipse-step-by-step-guide/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG project In Eclipse&lt;/a&gt; for Selenium test automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Create and Execute Test Cases in TestNG
&lt;/h2&gt;

&lt;p&gt;To demonstrate the usage of the TestNG framework for web automation testing, we use the same test scenario that we had demonstrated in the earlier section. The browser and platform combination also remains unchanged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to &lt;a href="https://todomvc.com/examples/react/#/" rel="noopener noreferrer"&gt;https://todomvc.com/examples/react/#/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the text “TestNG Sample Test” in the textbox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the exact text appears in the list below the textbox.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  package Test;

    import static org.testng.Assert.assertTrue;

    import java.net.MalformedURLException;
    import java.net.URL;

    import org.junit.Assert;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;

    public class TestNGDemo {
       public WebDriver driver;

       @BeforeClass
       public void setUp() throws Exception {
           System.setProperty("webdriver.chrome.driver", "YOUR CHROME DRIVER EXE PATH");
           driver = new ChromeDriver();
       }

       @BeforeMethod
       public void beforeMethod() {
           System.out.println("Before Method Setup");// for illustration
       }

       @Test
       public void testNGDemoTest() throws Exception {
           try { // Change it to production page
               int total_elements = 0;
               driver.get("https://todomvc.com/examples/react/#/");
               driver.findElement(By.className("new-todo")).sendKeys("TestNG Sample Test");
               driver.findElement(By.className("new-todo")).sendKeys(Keys.ENTER);
               total_elements = driver.findElements(By.xpath("//ul[@class='todo-list']/li//label")).size();
               Assert.assertEquals(1, total_elements);

           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
       }

       @AfterMethod
       public void afterMethod() {
           System.out.println("Äfter Method");
       }

       @AfterClass
       public void tearDown() throws Exception {
           driver.quit(); // for illustration
       }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code WalkThrough&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;@BeforeClass and @AfterClass annotation specify that the method code will be executed before and after the class is invoked. Generally, we specify configuration methods, initialize and close driver instances, etc., in these annotations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;@BeforeMethod and @AfterMethod annotation is used to invoke the method before and after execution of each of the test methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; annotation denotes the test methods same as in JUnit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;assertEquals() method passes if the expected result matches with the actual result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Watch this video to learn about the TestNG Annotations and how they help provide better structure and readability to the code.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/zI7Xbaj4RIs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run TestNG test cases
&lt;/h2&gt;

&lt;p&gt;TestNG test cases can be run via testng.xml or through any build tool (e.g., Maven, Ant, or Gradle). testng.xml gives more flexibility for test case execution as compared to the JUnit framework.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
    &amp;lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" &amp;gt;
    &amp;lt;suite name="TestNGTestCaseDemo"&amp;gt;
     &amp;lt;test name=""TestNGSeleniumDemo &amp;gt;
       &amp;lt;classes&amp;gt;
          &amp;lt;class name="Test.TestNGSeleniumDemo/&amp;gt;
       &amp;lt;/classes&amp;gt;
     &amp;lt;/test&amp;gt;
    &amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can run the XML file in Eclipse or by triggering the following command from the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   $ java org.testng.TestNG testing.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that the TestNG jar file path is set to Java ClassPath before running the tests from the command line.&lt;/p&gt;

&lt;p&gt;If you are intrigued to learn more about the other essentials of the TestNG framework, head over to the detailed &lt;a href="https://www.lambdatest.com/learning-hub/testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG tutorial&lt;/a&gt; on LambdaTest learning hub.&lt;/p&gt;

&lt;p&gt;This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium automation testing with JUnit.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the JUnit certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fWsCwrtElAw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Run JUnit Tests using TestNG in Selenium
&lt;/h2&gt;

&lt;p&gt;Before jumping on ‘How,’ let us first understand ‘why’ we need to run test cases using JUnit and TestNG in Selenium test automation. Here is the simplest answer to the above question&lt;br&gt;
‘Provision of extensive capabilities of TestNG over JUnit.’ TestNG was released much later than JUnit but offers numerous features like improved manageable test execution capabilities, better annotations to provide flexibility, and more.&lt;/p&gt;

&lt;p&gt;Here is a brief rundown of the &lt;a href="https://www.lambdatest.com/blog/testng-vs-junit-which-testing-framework-should-you-choose/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG vs JUnit&lt;/a&gt; comparison:&lt;/p&gt;

&lt;p&gt;1- Annotations: TestNG offers more annotations to make automation test case management more flexible when compared to JUnit. Although JUnit 5 has introduced a few new annotations to achieve more flexibility in test case management, we still need to see how it performs compared to JUnit.&lt;/p&gt;

&lt;p&gt;2- Grouping of Test Cases: TestNG supports the grouping of test cases if you wish to run only a set of test cases. This can be achieved with the help of groups parameters in &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; annotation. The same tag is specified in testng.xml with the name of the groups you wish to run.&lt;/p&gt;

&lt;p&gt;3- Parallel test case execution: TestNG supports parallel execution of test cases using multiple threads and classes using the “parallel” keyword in testng.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   junit.jupiter.execution.parallel.enabled = true
    junit.jupiter.execution.parallel.mode.default = concurrent

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here concurrent mode specifies parallel threads to be run for each test method. We can also set it to ‘default’ if we want a single thread for all methods. Test methods in such test classes are only executed concurrently if the &lt;a class="mentioned-user" href="https://dev.to/execution"&gt;@execution&lt;/a&gt;(CONCURRENT) annotation is present on the test class or method. &lt;a href="https://www.lambdatest.com/blog/create-testng-xml-file-execute-parallel-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Parallel test execution in TestNG&lt;/a&gt; is preferred since it helps you achieve test results at a much faster pace.&lt;/p&gt;

&lt;p&gt;4- Test case dependency: The dependsOnMethods parameter in &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; annotation is used to define the dependent method (or a group of methods). This is mostly used where one test method depends on the output of another test method(s). However, dependent tests is not a good practice when it comes to Selenium automation testing. Hence, it is recommended to follow &lt;a href="https://www.lambdatest.com/blog/selenium-best-practices-for-web-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium best practices&lt;/a&gt; to make the most out of the test automation framework.&lt;/p&gt;

&lt;p&gt;You can achieve dependency injection in JUnit 5, where the test methods are permitted to have parameters.&lt;/p&gt;

&lt;p&gt;As seen until now, TestNG has many advantages over JUnit 4 (which is still in extensive use). Many of us would like to harness the capabilities of TestNG so that tests can be partially or fully migrated to TestNG. Now the question is, How do you run test cases using JUnit and TestNG in Selenium?&lt;/p&gt;

&lt;p&gt;You might have ’N’ number of unit tests written in JUnit, which are integrated with the CI/CD pipeline. The test framework, the CI/CD pipeline, reporting, and everything are in place and running well before each release. Re-writing those test cases would lead to a significant increase in the costs. So what is the ideal solution to make the most out of JUnit, TestNG, and the corresponding CI/CD tool used in the project?&lt;/p&gt;

&lt;p&gt;Well, TestNG solves this problem by recognizing a number of JUnit test examples through the JUnit tag in the XML file. To put it in simple words, TestNG has built-in support for running JUnit test cases. We will discuss this in detail with the same example with the help of LambdaTest’s &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This JUnit Tutorial for beginners and professionals will help you learn how to use JUnit framework with Selenium and Java for performing Selenium automation testing.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/HXtC-a_4HAc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Parallel Test Execution of JUnit Test Cases in TestNG Using Remote Selenium Grid
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Parallel testing in Selenium&lt;/a&gt; helps you achieve better test coverage at an expedited pace. Though parallel test execution is not a key feature of JUnit, it can be achieved using certain methods, which we further discuss in this section.&lt;/p&gt;

&lt;p&gt;To make the execution of JUnit test cases more efficient, we can execute them in TestNG using a cloud-based remote Selenium Grid. Executing test cases using JUnit and TestNG in Selenium can be achieved in the same way as discussed earlier. However, a cloud-based Selenium Grid would ensure secure, fast, and stable test execution.&lt;/p&gt;

&lt;p&gt;For demonstrating how to run JUnit tests using TestNG on a cloud Selenium Grid, we consider the following test scenario:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to &lt;a href="https://todomvc.com/examples/react/#/" rel="noopener noreferrer"&gt;https://todomvc.com/examples/react/#/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the text “JUnit Parallel Test sample” in the textbox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the exact text appears in the list below the textbox.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For demonstrating the potential of parallel testing with JUnit and TestNG using Selenium cloud grid, we run the same test on multiple browser and platform combinations:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Platform&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;70.0&lt;/td&gt;
&lt;td&gt;WIN10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;14.0.2&lt;/td&gt;
&lt;td&gt;macOS Big Sur&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;76.0&lt;/td&gt;
&lt;td&gt;WIN8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let us first write the JUnit code to support the parallel execution of threads for each of the browser-platform combinations. To run a JUnit test on different browsers simultaneously, you will need to create a helper class that extends parameterized class (org.junit.runners.Parameterized) and implements RunnerScheduler class.&lt;/p&gt;

&lt;p&gt;To demonstrate this, we are using LambdaTest cloud-based Selenium Grid that offers &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-junit?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Automation Testing With JUnit&lt;/a&gt; across 2000+ browsers and operating systems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   package Test;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.TimeUnit;
    import org.junit.runners.Parameterized;
    import org.junit.runners.model.RunnerScheduler;
    public class Parallelized extends Parameterized {
       private static class ThreadPoolScheduler implements RunnerScheduler {
           private ExecutorService executor;
           public ThreadPoolScheduler() {
               String threads = System.getProperty("junit.parallel.threads", "15");
               int numThreads = Integer.parseInt(threads);
               executor = Executors.newFixedThreadPool(numThreads);
           }

           public void finished() {
               executor.shutdown();
               try {
                   executor.awaitTermination(10, TimeUnit.MINUTES);
               } catch (InterruptedException exc) {
                   throw new RuntimeException(exc);
               }
           }

           public void schedule(Runnable childStatement) {
               executor.submit(childStatement);
           }
       }
       public Parallelized(Class&amp;lt;?&amp;gt; klass) throws Throwable {
           super(klass);
           setScheduler(new ThreadPoolScheduler());
       }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will write the script to implement the above-mentioned test scenario. The Parallelized class will be passed as a parameter in @RunWith annotation. To execute the test case on LamdaTest, you have to provide our username and access key, which is available in the &lt;a href="https://accounts.lambdatest.com/detail/profile?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug05_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest profile&lt;/a&gt; section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    package Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Platform;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.jupiter.api.RepeatedTest;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.LinkedList;
    import java.util.List;

    [@RunWith](http://twitter.com/RunWith)(Parallelized.class)
    public class JunitParallelExecutionDemo {
       public static String username = "YOUR_USER_NAME;
       public static String accessKey = "YOUR_ACCESS_KEY";
       public String gridURL = "[@hub](http://twitter.com/hub).lambdatest.com/wd/hub";
       public String platform;
       public String browserName;
       public String browserVersion;
       public RemoteWebDriver driver = null;
       boolean status = false;

    [@Parameterized](http://twitter.com/Parameterized).Parameters
       public static LinkedList&amp;lt;String[]&amp;gt; getEnvironments() throws Exception {
           LinkedList&amp;lt;String[]&amp;gt; env = new LinkedList&amp;lt;String[]&amp;gt;();
           env.add(new String[] { "WIN10", "chrome", "70.0" });
           env.add(new String[] { "macOS Big Sur", "safari", "14.0.2" });
           env.add(new String[] { "WIN8", "firefox", "62.0" });
           return env;
       }

    public JunitParallelExecutionDemo(String platform, String browserName, String browserVersion) {
           this.platform = platform;
           this.browserName = browserName;
           this.browserVersion = browserVersion;
       }

    [@Before](http://twitter.com/Before)
       public void setUp() throws Exception {
           DesiredCapabilities capabilities = new DesiredCapabilities();
           capabilities.setCapability("browserName", browserName);
           capabilities.setCapability("version", browserVersion);
           capabilities.setCapability("platform", platform);
           capabilities.setCapability("build", "JUnitRepeatedTestSample");
           capabilities.setCapability("name", "JUnitRepeatedTestSample");
           capabilities.setCapability("network", true); // To enable network logs
           capabilities.setCapability("visual", true); // To enable step by step screenshot
           capabilities.setCapability("video", true); // To enable video recording
           capabilities.setCapability("console", true); // To capture console logs
           try {
               driver = new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + gridURL), capabilities);
           } catch (MalformedURLException e) {
               System.out.println("Invalid grid URL");
           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
       }
       [@Test](http://twitter.com/Test)
       [@RepeatedTest](http://twitter.com/RepeatedTest)(value=2)
       public void testParallel() throws Exception {
           try { // Change it to production page
               int total_elements=0;
               driver.get("[https://todomvc.com/examples/react/#/](https://todomvc.com/examples/react/#/)");
               driver.findElement(By.className("new-todo")).sendKeys("Lambdatest Cross Browser Testing");;
               total_elements = driver.findElements(By.xpath("//ul[[@class](http://twitter.com/class)='todo-list']/li")).size();
               Assert.assertEquals(1, total_elements);

    } catch (Exception e) {
               System.out.println(e.getMessage());
           }
       }

    [@After](http://twitter.com/After)
       public void tearDown() throws Exception {
               driver.quit();
           }

    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the above test case can be run using JUnit and TestNG in Selenium, the same way as we discussed earlier. We will provide junit=”true” in the suite tag, and we are done!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
    &amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)" &amp;gt;
    &amp;lt;suite name = "Parallel Tests" junit="true"&amp;gt;
     &amp;lt;test name="JunitParallelExecutionDemo"&amp;gt;
       &amp;lt;classes&amp;gt;
          &amp;lt;class name="Test.JunitParallelExecutionDemo"/&amp;gt;
       &amp;lt;/classes&amp;gt;
    &amp;lt;/test&amp;gt;
    &amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see from the below execution log for the above test case ran on three different browsers-platforms combination-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nv0z21ji10hmpmsenmx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nv0z21ji10hmpmsenmx.png" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see in the screenshot, the test has run on the given browsers in parallel. We can also see the execution video by selecting the particular execution and click on the video on the right side. This would help to find the issue in case there is any failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey! Are you using &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; for automation testing? Run your Playwright test scripts instantly on 50+ browser/OS combinations using the LambdaTest cloud!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfkjilircna38vjjg5j6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxfkjilircna38vjjg5j6.png" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To summarize, we have seen the two testing frameworks -JUnit and TestNG and how they are different. Also, what are the capabilities of TestNG, and why would we need to run test cases using JUnit and TestNG in Selenium test automation. We have also explained how to do that with the help of a JUnit test example. This is how we can utilize existing test cases with the enhanced abilities of TestNG.&lt;/p&gt;

&lt;p&gt;I hope this blog will help you run test cases using JUnit and TestNG in Selenium and find ways to scale the automation test suite using their extensive capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Testing!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>testing</category>
    </item>
    <item>
      <title>Complete JUnit 5 Mockito Tutorial For Unit Testing</title>
      <dc:creator>Ruchira Shukla</dc:creator>
      <pubDate>Thu, 04 Aug 2022 13:11:00 +0000</pubDate>
      <link>https://dev.to/testmuai/complete-junit-5-mockito-tutorial-for-unit-testing-4mgg</link>
      <guid>https://dev.to/testmuai/complete-junit-5-mockito-tutorial-for-unit-testing-4mgg</guid>
      <description>&lt;p&gt;Mockito is a &lt;a href="https://www.lambdatest.com/blog/9-of-the-best-java-testing-frameworks-for-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;unit testing framework&lt;/a&gt; for Java that simplifies the task of automation testing. It makes unit testing highly effective with clean tests, thanks to dependency injection and compile-time checks. In addition, Mockito helps improve the test independence of components being developed by helping you create objects that have no dependencies on a test-specific configuration. The most popular way of using Mockito is within the JUnit framework to help you write better tests.&lt;/p&gt;

&lt;p&gt;For starters, mocking in unit testing is used for isolating the AUT (Application Under Test) from external dependencies. Mocking must be leveraged when implementation of external dependencies is not yet completed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ASdOVY5lCQge7DViYsnYQyg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ASdOVY5lCQge7DViYsnYQyg.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this JUnit 5 Mockito tutorial, we will see how Mockito can be used with the JUnit unit testing framework for mocking in JUnit 5.&lt;/p&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started with Mockito and JUnit 5
&lt;/h2&gt;

&lt;p&gt;Mockito is an open-source &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework that internally uses Java Reflection API to create mock objects. Mock objects are dummy objects used for actual implementation. The main purpose of using a dummy object is to simplify the development of a test by mocking external dependencies and using them in the code.&lt;/p&gt;

&lt;p&gt;As per my experience, you should mock objects in unit tests when the real object has a non-deterministic behavior or the real object is a callback function or the real object is yet to be implemented.&lt;/p&gt;

&lt;p&gt;In this JUnit 5 Mockito tutorial, we will use Mockito with JUnit for performing Selenium automation testing. In case you are starting with JUnit, look at this article on &lt;a href="https://www.lambdatest.com/blog/setup-junit-environment/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to setup JUnit environment for your first test?&lt;/a&gt;. However, you can also go through the &lt;a href="https://www.lambdatest.com/learning-hub/junit-tutorial?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium JUnit tutorial&lt;/a&gt; to check out the basics of JUnit, from writing your first test to running tests in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; with examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mockito Installation
&lt;/h2&gt;

&lt;p&gt;When you use Mockito in your unit tests, you will need to download the jar file and place it in a path that your build system can find. Mockito is available in two versions: mockito-core (which contains only the core of Mockito, and mockito-all (which contains all modules).&lt;/p&gt;

&lt;p&gt;The preferred way of installing Mockito is to declare a dependency on mockito-core with a build system of choice. The second best way is to download the artifacts using a manual approach and add them to the classpath. You can also add dependencies to your existing Maven or Gradle project.&lt;/p&gt;

&lt;p&gt;Add the following dependencies in your pom.xml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;dependency&amp;gt; &amp;lt;groupId&amp;gt;org.mockito&amp;lt;/groupId&amp;gt; &amp;lt;artifactId&amp;gt;mockito-core&amp;lt;/artifactId&amp;gt; &amp;lt;version&amp;gt;4.1.0&amp;lt;/version&amp;gt; &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt; &amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When using Gradle, this can be achieved by declaring the following dependency to your build.gradle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  compile("org.mockito:mockito-core:4.1.0")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The latest version of Mockito when writing this article is 4.1.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Annotations in Mockito
&lt;/h2&gt;

&lt;p&gt;Like &lt;a href="https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit annotations&lt;/a&gt;, Mockito annotations are used to specify the behavior of the test code. It allows the users to focus more on their logic while still testing the code very effectively. This section of the JUnit 5 Mockito tutorial mainly focuses on Mockito annotations and how to use them in Selenium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. @Mock annotation in Mockito&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mock annotation is used to create a mock object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Mock](http://twitter.com/Mock)
    ToDoService serviceMock;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The @Mock annotation is always used with @RunWith, a class-level annotation. We will see in detail how both annotations are used to create and use a mock object in the next segment.&lt;/p&gt;

&lt;p&gt;For now, let’s see the following syntactic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@RunWith](http://twitter.com/RunWith)(MockitoJUnitRunner.class) 
    public class DemoMock { 
    ..... 
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. &lt;a class="mentioned-user" href="https://dev.to/spy"&gt;@spy&lt;/a&gt; annotation in Mockito&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spy annotation is used to create a real object and spy on that real object. This would help to call all the object methods while still tracking every interaction that is being mocked.&lt;/p&gt;

&lt;p&gt;Below is the simple implementation of &lt;a class="mentioned-user" href="https://dev.to/spy"&gt;@spy&lt;/a&gt; annotation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Spy](http://twitter.com/Spy)
    List&amp;lt;String&amp;gt; myList = new ArrayList&amp;lt;String&amp;gt;();

    [@Test](http://twitter.com/Test)
    public void usingSpyAnnotation() {
       myList.add("Hello, This is LambdaTest");
       Mockito.verify(spyList).add("Hello, This is LambdaTest");
       assertEquals(1, spyList.size());
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. @Captor annotation in Mockito&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Captor annotation is used to create an ArgumentCaptor instance to capture method argument values for further assertions.&lt;/p&gt;

&lt;p&gt;Here is a simple implementation of @Captor annotation that captures MyMap’s key and values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Mock](http://twitter.com/Mock)
    HashMap&amp;lt;String, Integer&amp;gt; MyMap;
    [@Captor](http://twitter.com/Captor)
    ArgumentCaptor&amp;lt;String&amp;gt; keyCaptor;
    [@Captor](http://twitter.com/Captor)
    ArgumentCaptor&amp;lt;Integer&amp;gt; valueCaptor;
    [@Test](http://twitter.com/Test)
    public void ArgumentCaptorTest()
    {
       hashMap.put("A", 10);
       Mockito.verify(MyMap).put(keyCaptor.capture(), valueCaptor.capture());
       assertEquals("A", keyCaptor.getValue());
       assertEquals(new Integer(10), valueCaptor.getValue());
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. @InjectMocks annotation in Mockito&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;InjectMocks annotation is used to mock a class with all its dependencies. This is quite useful to test the behavior completely.&lt;/p&gt;

&lt;p&gt;In the below example, we will use @InjectMock Countries into Continent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Mock](http://twitter.com/Mock)
    Map&amp;lt;String, String&amp;gt; Countries;

    [@InjectMocks](http://twitter.com/InjectMocks)
    MyDictionary dic = new Continent();

    [@Test](http://twitter.com/Test)
    public void UseInjectMocksAnnotation() {
       Mockito.when(Countries.get("India")).thenReturn("asia");

       assertEquals("asia", dic.getContinent("India"));
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have seen different Mockito annotations, let’s deep-dive into creating Mocks in the Mockito framework.&lt;/p&gt;

&lt;p&gt;However, if you are intrigued to know more about JUnit Annotations in Selenium, you can go through the following video from the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with more such videos on the &lt;a href="https://www.youtube.com/playlist?list=PLZMWkkQEwOPn68qzCGJl07ZbnI7Ix5zKU?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit tutorial with Selenium&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress Testing&lt;/a&gt;, and more.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/tpBX5w0I_Jo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create Mocks in Mockito?
&lt;/h2&gt;

&lt;p&gt;In this section of the JUnit 5 Mockito tutorial, we will see different ways to create Mocks in the Mockito framework. In Mockito, we can create mock objects in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Using @Mock annotation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using Mock() method&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Using @Mock annotation to create Mocks
&lt;/h2&gt;

&lt;p&gt;@Mock annotation minimizes repetitive mock objects and makes more readable test code and verification errors. It is available in the org.mockito package. Here is the code snippet of @mock annotation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Mock](http://twitter.com/Mock)
    ToDoService serviceMock;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using @Mock method to create Mocks
&lt;/h2&gt;

&lt;p&gt;The Mockito.mock() method allows us to create a mock object of classes and interfaces. Here is the code snippet for a simple class mock:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    MyList listMock = mock(MyList.class);
    when(listMock.add(anyString())).thenReturn(false);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code snippet, MyList is a class for which we have created a mock object by passing that as a parameter in the mock() method. The second line sets an expectation. When the add() method of MyList class is called, it has to return false.&lt;/p&gt;

&lt;p&gt;To understand this more clearly, let’s take an example of an eCommerce application. Let’s assume a scenario where you have to test the checkout feature. There is a class Order which has a method checkout() that finalizes the order and processes the payment. We are deliberately overlooking other conditions for the sake of simplicity.&lt;/p&gt;

&lt;p&gt;So the Order class would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class Order {

           public Order() {
           }

           public String checkout(PaymentProviderService payment) {
               try {
                   return payment.processPayment().equalsIgnoreCase("Approved") ? "Success" : "Failure";
               }
               catch(Exception e) {
                   return "Exception occurred at payment provider service when trying to checkout";
               }
           }
       }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the checkout() method uses PaymentProviderService class for payment processing. The success or failure of checkout is based on the method processPayment().&lt;/p&gt;

&lt;p&gt;So if we want to write test cases for checkout functionality, we also need to create an instance of the PaymentProviderService class. But we don’t want to depend on this class to start writing our unit tests. In this case, we would create a mock object of the PaymentProviderService class and continue writing tests for the Order class.&lt;/p&gt;

&lt;p&gt;Here is the code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class OrderTests {

           [@Test](http://twitter.com/Test)
           public void checkoutOrderSuccessOnPaymentSuccess() {

               Order order = new Order();
               PaymentService ppMock = mock(PaymentService.class);
               when(ppMock.processPayment()).thenReturn("Approved");

               Assert.assertEquals(
                   "Success",
                   order.checkout(ppMock)
               );
           }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have created a test case for the Order class in the above code, which tests the successful order placement scenario.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    PaymentProviderService ppMock = mock(PaymentProviderService.class);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above line creates a mock object of the PaymentProviderService class. Now we can use this object to call the processPayment() method. We can write the expected behavior using when…thenReturn as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; when(ppMock.processPayment()).thenReturn("Approved");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, we can assert the expected and actual outputs and perform the desired function. Likewise, we have created 4 unit tests for the Order class. The output of those tests on running them on IDE is shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5vVkBhmHDonkn8qrr27xJw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A5vVkBhmHDonkn8qrr27xJw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Are you using &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; for automation testing? Run your Playwright test scripts instantly on 50+ browser/OS combinations using the LambdaTest cloud. Sign up for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use Mockito with JUnit 5 extensions?
&lt;/h2&gt;

&lt;p&gt;This section of the JUnit 5 Mockito tutorial is devoted to the usage of Mockito with JUnit 5. It shows how to add a mock object to a test case and verify its behavior with JUnit 5. JUnit 5 has an extension model that supports Mockito out-of-the-box. The &lt;a href="https://www.lambdatest.com/blog/junit5-extensions/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit 5 extension&lt;/a&gt; model allows users to provide custom annotations and behaviors for test doubles.&lt;/p&gt;

&lt;p&gt;To start with, JUnit Jupiter dependencies need to be added apart from mockito-core dependencies. So following dependencies have to be added in pom.xml(for Maven):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;dependency&amp;gt;
       &amp;lt;groupId&amp;gt;org.mockito&amp;lt;/groupId&amp;gt;
       &amp;lt;artifactId&amp;gt;mockito-junit-jupiter&amp;lt;/artifactId&amp;gt;
       &amp;lt;version&amp;gt;4.1.0&amp;lt;/version&amp;gt;
       &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how the dependencies can be added for Gradle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    dependencies{
    testImplementation('org.mockito:mockito-core:4.1.0')

The extension eliminates the need for the MockitoAnnotations.openMocks() method call. So the above example can be modified as:

    [@ExtendWith](http://twitter.com/ExtendWith)(MockitoExtension.class)
    public class OrderTestsUsingExtension {

               [@Test](http://twitter.com/Test)
               public void checkoutOrderSuccessOnPaymentSuccess() {

                   Order order = new Order();
                   PaymentProviderService ppMock = mock(PaymentProviderService.class);
                   when(ppMock.processPayment()).thenReturn("Approved");

                   Assert.assertEquals(
                       "Success",
                       order.checkout(ppMock)
                   );
               }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s simple, isn’t it? This makes our code more readable and clean. Also, it can detect incorrect stubbing.&lt;/p&gt;

&lt;p&gt;The next section of this JUnit 5 Mockito tutorial, will showcase &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing in Selenium&lt;/a&gt; using Mockito and JUnit.&lt;/p&gt;

&lt;p&gt;This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium &lt;a href="https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing with JUnit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the JUnit certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fWsCwrtElAw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to perform parallel testing using Mockito and JUnit 5 on cloud Selenium Grid
&lt;/h2&gt;

&lt;p&gt;JUnit 5 has the much-awaited capability of executing tests parallely, which significantly reduces the execution time. This is a life savior for testers as we have a huge no. of test cases in the real world. Leveraging this capability using an &lt;a href="https://www.lambdatest.com/selenium-grid-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online Selenium Grid&lt;/a&gt; like LambdaTest would be more efficient.&lt;/p&gt;

&lt;p&gt;Selenium testing tools like LambdaTest, allow you to perform &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; on more than 3000 &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt; and operating system combinations.&lt;/p&gt;

&lt;p&gt;Here is a quick video tutorial on the real-time browser testing.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/hJ-eP8TcGuY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this section of the JUnit 5 Mockito tutorial, we will take a simple example to demonstrate parallel testing with Mockito and JUnit 5:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem Statement&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;https://www.lambdatest.com&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate the page title is “Most Powerful Cross Browser Testing Tool Online | LambdaTest.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter username and password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the login button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate successful login by “Welcome — LambdaTest” message.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will be executing this test case on the following browsers, versions, and platform combinations using LambdaTest remote Selenium Grid:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Browser&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Platform&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Chrome&lt;/td&gt;
&lt;td&gt;70.0&lt;/td&gt;
&lt;td&gt;WIN10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safari&lt;/td&gt;
&lt;td&gt;14.0.2&lt;/td&gt;
&lt;td&gt;macOS Big Sur&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firefox&lt;/td&gt;
&lt;td&gt;76.0&lt;/td&gt;
&lt;td&gt;WIN10&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package MockitoDemo.MockitoDemo;
    import org.junit.jupiter.api.AfterAll;
    import org.junit.jupiter.api.AfterEach;
    import org.junit.jupiter.api.Assertions;
    import org.junit.jupiter.api.BeforeAll;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.Test;
    import org.junit.jupiter.api.parallel.Execution;
    import org.junit.jupiter.api.parallel.ExecutionMode;
    import org.junit.jupiter.params.ParameterizedTest;
    import org.junit.jupiter.params.provider.Arguments;
    import org.junit.jupiter.params.provider.MethodSource;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import java.util.stream.Stream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    import static org.junit.jupiter.params.provider.Arguments.arguments;
    @Execution(ExecutionMode.CONCURRENT)
    public class CrossbrowserDemo {
    String username = "YOUR_USER_NAME";
           String accesskey = "YOUR_ACCESS_KEY";

          static RemoteWebDriver driver = null;
          String gridURL = "@hub.lambdatest.com/wd/hub";
          String urlToTest = "https://www.lambdatest.com/";

          @BeforeAll
          public static void start() {
              System.out.println("=======Starting junit 5 tests in LambdaTest  Grid========");
          }

          @BeforeEach
          public void setup(){
              System.out.println("=======Setting up drivers and browser========");
          }

          public void browser_setup(String browser) {
              System.out.println("Setting up the drivers and browsers");
              DesiredCapabilities capabilities = new DesiredCapabilities();

              if(browser.equalsIgnoreCase("Chrome")) {
                  capabilities.setCapability("browserName", "chrome");    //To specify the browser
                  capabilities.setCapability("version", "70.0");        //To specify the browser version
                  capabilities.setCapability("platform", "win10");        // To specify the OS
                  capabilities.setCapability("build", "Running_Junit5Tests_In_Grid_Chrome");               //To identify the test
                  capabilities.setCapability("name", "JUnit5Tests_Chrome");
                  capabilities.setCapability("network", true);        // To enable network logs
                  capabilities.setCapability("visual", true);            // To enable step by step screenshot
                  capabilities.setCapability("video", true);            // To enable video recording
                  capabilities.setCapability("console", true);            // To capture console logs
              }
              if(browser.equalsIgnoreCase("Firefox")) {
                  capabilities.setCapability("browserName", "Firefox");  //To specify the browser
                  capabilities.setCapability("version", "76.0");    //To specify the browser version
                  capabilities.setCapability("platform", "win10");   // To specify the OS
                  capabilities.setCapability("build", "Running_Junit5Tests_In_Grid_Firefox");    //To identify the test
                  capabilities.setCapability("name", "JUnit5Tests_Firefox");
                  capabilities.setCapability("network", true);      // To enable network logs
                  capabilities.setCapability("visual", true);       // To enable step by step screenshot
                  capabilities.setCapability("video", true);        // To enable video recording
                  capabilities.setCapability("console", true);      // To capture console logs

              }
              if(browser.equalsIgnoreCase("Safari")) {
                  capabilities.setCapability("browserName", "Safari");  //To specify the browser
                  capabilities.setCapability("version", "14.0.2");    //To specify the browser version
                  capabilities.setCapability("platform", "macOS Big Sur");   // To specify the OS
                  capabilities.setCapability("build", "Running_Junit5Tests_In_Grid_Safari");    //To identify the test
                  capabilities.setCapability("name", "JUnit5Tests_Firefox");
                  capabilities.setCapability("network", true);      // To enable network logs
                  capabilities.setCapability("visual", true);       // To enable step by step screenshot
                  capabilities.setCapability("video", true);        // To enable video recording
                  capabilities.setCapability("console", true);      // To capture console logs

              }
              try {
                  driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities);
              } catch (MalformedURLException e) {
                  System.out.println("Invalid grid URL");
              } catch (Exception e) {
                  System.out.println(e.getMessage());
              }

          }

          @ParameterizedTest
          @MethodSource("browser")
          public void launchAndVerifyTitle_Test(String browser) {
              browser_setup(browser);
              String methodName = Thread.currentThread()
                      .getStackTrace()[1]
                      .getMethodName();
              driver.get(urlToTest);
              driver.manage().window().maximize();
              driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
              String actualTitle = driver.getTitle();
              System.out.println("The page title is "+actualTitle);
              String expectedTitle ="Most Powerful Cross Browser Testing Tool Online | LambdaTest";
              System.out.println("Verifying the title of the webpage started");
              Assertions.assertEquals(expectedTitle, actualTitle);
              System.out.println("The webpage has been launched and the title of the webpage has been veriified successfully");
              System.out.println("********Execution of "+methodName+" has ended********");
          }

          @ParameterizedTest
          @MethodSource("browser")
          public void login_Test(String browser) {
              browser_setup(browser);

              String methodName = Thread.currentThread()
                      .getStackTrace()[1]
                      .getMethodName();
              driver.get(urlToTest);
              driver.manage().window().maximize();
              driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
              WebElement login = driver.findElement(By.xpath("//a[text()='Login']"));
              login.click();
              WebElement username = driver.findElement(By.xpath("//input[@name='email']"));
              WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
              WebDriverWait wait = new WebDriverWait(driver,20);
              wait.until(ExpectedConditions.visibilityOf(username));
              username.clear();
              username.sendKeys("ruchirashukla89@gmail.com");
              password.clear();
              password.sendKeys("ruchira@89");
              WebElement loginButton = driver.findElement(By.xpath("//button[text()='Login']"));
              loginButton.click();
              driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
              String actual = driver.getTitle();
              String expected = "Welcome - LambdaTest";
              Assertions.assertEquals(expected, actual);
              System.out.println("The user has been successfully logged in");
              System.out.println("********Execution of "+methodName+" has ended********");
          }

          @ParameterizedTest
          @MethodSource("browser")
          public void logo_Test(String browser) {
              browser_setup(browser);
              String methodName = Thread.currentThread()
                      .getStackTrace()[1]
                      .getMethodName();
              System.out.println("********Execution of "+methodName+" has been started********");
              System.out.println("Launching LambdaTest website started..");
              driver.get(urlToTest);
              driver.manage().window().maximize();
              driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
              System.out.println("Verifying of webpage logo started..");

              WebElement logo = driver.findElement(By.xpath("//*[@id=\"header\"]/nav/div/div/div[1]/div/a/img"));
              boolean is_logo_present = logo.isDisplayed();
              if(is_logo_present) {
                  System.out.println("The logo of LambdaTest is displayed");
              }
              else {
                  Assertions.assertFalse(is_logo_present,"Logo is not present");
              }
              System.out.println("********Execution of "+methodName+" has ended********");
          }

          @AfterEach
          public void tearDown() {
              System.out.println("Quitting the browsers has started");
              driver.quit();
              System.out.println("Quitting the browsers has ended");
          }

          @AfterAll
          public static void end() {
              System.out.println("Tests ended");
          }

          static Stream&amp;lt;Arguments&amp;gt; browser() {
              return Stream.of(
                      arguments("Chrome"),
                      arguments("Firefox"),
                      arguments("Safari")
              );
          }

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code Walkthrough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Three tests will run in parallel in the above code on the mentioned browser OS combinations.&lt;/p&gt;

&lt;p&gt;The &lt;a class="mentioned-user" href="https://dev.to/execution"&gt;@execution&lt;/a&gt;(ExecutionMode.CONCURRENT) annotation defines the parallel mode in JUnit 5. The LambdaTest remote Selenium Grid initiates the execution based on the arguments defined in the capabilities.&lt;/p&gt;

&lt;p&gt;The @ParameterizedTest annotation defines that the annotated method is parameterized where the @MethodSource annotation is used to provide the method name, which is used as a source of parameter values.&lt;/p&gt;

&lt;p&gt;At last, the browser() method, which is the method source, has the browser names as the arguments.&lt;/p&gt;

&lt;p&gt;After execution, we will get logs as below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ARjK-FbAtjyNgDGljrtz-iQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3200%2F1%2ARjK-FbAtjyNgDGljrtz-iQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, three tests are executed in parallel on three different browsers where they took around 60 seconds to execute.&lt;/p&gt;

&lt;p&gt;We can also get the video of each run to find the issue if a test fails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhocmtr227qv0fxyjujdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhocmtr227qv0fxyjujdg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, if you’re curious to know more about performing &lt;a href="https://www.lambdatest.com/blog/parallel-testing-with-junit5-and-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing with JUnit 5 and Selenium&lt;/a&gt;, this video will help you get started. This video will guide you through different parallel parameters in &lt;a href="https://www.lambdatest.com/junit-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit testing&lt;/a&gt;, including methods — execute test methods in separate threads and classes — to execute test classes in separate threads.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IBWJCk2SHYk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Test on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug04_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Automation Testing&lt;/a&gt; Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this JUnit 5 Mockito tutorial, we have gone through the basics of the Mocking and Mockito framework. Also, what are different annotations in Mockito and their use cases. In JUnit 5, the creation of mocks using Mockito has been made more simple by extension. We have also discussed the parallel execution of test cases in JUnit5 using LambdaTest cloud Selenium Grid. Though Mockito is highly utilized in unit testing, we can also leverage its extensive capabilities in integrating those unit tests for Selenium automation testing.&lt;/p&gt;

&lt;p&gt;How have you used Mockito in your testing? Let us know in the comments below.&lt;/p&gt;

&lt;p&gt;Happy Testing!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>testing</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>15 Most Important Mobile App Testing Scenarios</title>
      <dc:creator>Ruchira Shukla</dc:creator>
      <pubDate>Wed, 03 Aug 2022 11:39:13 +0000</pubDate>
      <link>https://dev.to/testmuai/15-most-important-mobile-app-testing-scenarios-1omc</link>
      <guid>https://dev.to/testmuai/15-most-important-mobile-app-testing-scenarios-1omc</guid>
      <description>&lt;p&gt;Mobile app testing is critical in the mobile development lifecycle. Developers and app testers should think of different &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;mobile app testing&lt;/a&gt; scenarios before making them live. This is particularly important given the number of apps released daily. According to Statista, mobile app downloads worldwide have increased to 218 billion in 2020.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2932%2F1%2As3CK66-zoy18CS9bUk2-tQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2932%2F1%2As3CK66-zoy18CS9bUk2-tQ.png" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This has led to a demand for delivering high-quality mobile applications to stand out in the crowd and get maximum traffic. In this blog, we will discuss the different mobile app testing scenarios. Continuously upgrading Mobile OS, new devices, and localization challenges make a app tester’s job more challenging.&lt;/p&gt;

&lt;p&gt;To cater to this, it is crucial to create intelligent and efficient mobile app test scenarios which uncover the issues which can impact the user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey! This Playwright testing tutorial will guide you through the setup of the &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; test framework, which will enable you to write &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;end-to-end testing&lt;/a&gt; for your future projects. Click on the link to learn more!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Test Case
&lt;/h2&gt;

&lt;p&gt;A test case is a more granular level of testing where the &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;app tester&lt;/a&gt; performs various operations on the app to ensure that the given functionality works fine. This helps in understanding, tracking, and resolving quality issues. In short, test cases test the given scenario.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Test Scenario
&lt;/h2&gt;

&lt;p&gt;A Test scenario is a broader term and is often tied up with the user stories in the agile model. Test scenario helps engineers to test the mobile app with real-world use cases. Testers similarly execute scenarios as the end-user would use the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Create Mobile App Testing Scenarios?
&lt;/h2&gt;

&lt;p&gt;Test scenarios are created to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It assures complete test coverage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All the stakeholders approve the scenarios. Therefore every person involved is on the same page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They help determine the end-to-end use case of the Application and test everything accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When not to create a Mobile App Testing Scenarios?
&lt;/h2&gt;

&lt;p&gt;Test scenarios are not helpful in the below-mentioned cases.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;When the application is complicated or unstable or has a time crunch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you have a Scrum or Kanban methodology.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test Scenario should not be created to fix a new bug fix or during regression testing.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  15 Important Mobile App Testing Scenarios
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Functional Mobile Testing Scenario
&lt;/h2&gt;

&lt;p&gt;Along with the usual test scenarios which tests the basic functionality, there are some mobile app testing scenarios which one should consider while performing functional testing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ensure that mobile works in multitask mode when needed. For example, while using the app, if the user gets a call, he should perform the expected actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test that the AUT is not consuming other apps’ memory and not stopping the activities of other apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Page scroll, swipe is working as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check that the app’s automatic startup is working as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check that auto-logout is working as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigation between various modules should work as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test that the app’s social networking options such as sharing, posting, login are working correctly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  UI Mobile Testing Scenario
&lt;/h2&gt;

&lt;p&gt;UI testing can be tricky for mobile apps as one has to check for the component placement on a comparatively smaller screen. As all the web applications tend to be responsive now, one has to make sure that the layout, placement, and functionality are working as expected. Along with that, a few other mobile app testing scenarios must be noted.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Validate that text is not cut off and must be fitted on the screen.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that all popups, alert messages, and error messages are meaningful and correct.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate the carousel, navigation through menu, and swipe functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The page should not take more than five seconds to load, if it does, it should have a progress bar that allows the user to comprehend the scenario.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check for spelling &amp;amp; grammatical errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check for image sizes, image rendering, and company logo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the screen allows editing without saving, it must show a message to save details to the user when navigating to another screen without saving.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If there is lazy loading, check if the content loads without a lag when the user scrolls up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that data does not ghost off when moving the app to the background while filling a form.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Compatibility Mobile Testing Scenario
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check for the interrupt conditions like incoming calls, messages, or notifications while using the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The app should go into the background if there is an incoming call. After the call disconnects, it should again resume as it was before.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the phone’s essential functions like alarm, storing messages, sending/receiving messages are all working as expected while using the app.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey, Also learn what &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is and its benefits for automated cross browser testing.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Mobile Testing Scenario
&lt;/h2&gt;

&lt;p&gt;Performance of the app is critical as the purpose of convenient access would be lost if the app does not perform well.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Validate the performance of the application by changing the network to 2G,3G, 4G, 5G, and wifi.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate the CPU consumption while using the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate how many parallel users would crash the app to benchmark performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform the load testing on individual API calls and validate how the application behaves under a certain load.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Usability Mobile Testing Scenario
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check for the font size, button size, and content format so that it is accessible effortlessly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inform the client while downloading a lot of data which might not be favorable for the performance of an app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the app should have easy navigations which do not confuse users.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Security Mobile Testing Scenario
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Validate the flow for security vulnerabilities that involve the user’s personally identifiable data, such as mobile number, email, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the data is secured and encrypted, sent to and back from the server over the network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that no confidential data is stored without encryption and visible/accessible.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Battery &amp;amp; Data Mobile Testing Scenario
&lt;/h2&gt;

&lt;p&gt;Testing the app against data usage and power consumption should also be considered, as it should not drain the battery while running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recoverability Mobile Testing Scenario
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Validate that the app resumes the last operation in case of a hard reboot.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test what happens in case of a crash between transactions or any R/W function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Career &amp;amp; Network Connectivity Testing
&lt;/h2&gt;

&lt;p&gt;Test how well the app connects with the network and mobile data career online.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation &amp;amp; Resource usage Testing
&lt;/h2&gt;

&lt;p&gt;Test what resources are required to install the app and if the installation process is user-friendly and quick. Also, test that there is no crash during installation and it’s smooth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Localization and Time Zone Testing
&lt;/h2&gt;

&lt;p&gt;If an app supports different locals, the testers should also test the app for localization settings. The labels, functional flows, and other features should work as expected in different languages. Similarly, all the features should work as expected while operating in different time zones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Certification Mobile Testing Scenario
&lt;/h2&gt;

&lt;p&gt;Ensure that the app adheres to the guidelines of the Android or iOS phones platforms when installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Restrict/Allow Permission Testing
&lt;/h2&gt;

&lt;p&gt;Verify that the app adheres to the user permission settings for accessing the phone’s features such as contacts, camera, gallery, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Touch and Single Touch Testing
&lt;/h2&gt;

&lt;p&gt;Thoroughly test the multi-touch features such as pinch to zoom or pinch to shrink, etc., and create plenty of test cases for this for every applicable screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mobile Testing Strategy
&lt;/h2&gt;

&lt;p&gt;We have already discussed test scenarios for mobile app testing. We know that mobile devices have different OS and versions. The question is how to test the app for such a huge number of devices.&lt;/p&gt;

&lt;p&gt;The effective mobile testing strategy should aim for maximum coverage with a reasonable device investment. We can use virtual testing platforms of emulators and simulators or use &lt;a href="https://www.lambdatest.com/real-device-cloud?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;real device cloud&lt;/a&gt; which is nothing but real devices hosted on the cloud.&lt;/p&gt;

&lt;p&gt;There are different types of mobile virtual testing platforms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;iOS and &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Android Emulator&lt;/a&gt;Online — Emulates different mobile devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.lambdatest.com/browser-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Browser Emulator Online&lt;/a&gt; — Emulates different browsers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OS Emulators — Provided by respective OS designers; Android by Google, Windows Phone by Microsoft, and iOS emulator by Apple.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Using Real Device Cloud
&lt;/h2&gt;

&lt;p&gt;App testers should select the real devices based on the current market research data on the usage of devices. The devices which are most popular among users should be selected for testing.&lt;/p&gt;

&lt;p&gt;This also holds good for the OS versions. LambdaTest allows you to test apps on real devices using real device cloud.&lt;/p&gt;

&lt;p&gt;Looking to perform Android and iOS app testing on Real Device Cloud, check out our video below –&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vDHFbEjXxdc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Automation Testing
&lt;/h2&gt;

&lt;p&gt;Test engineers should also consider automating the functional/regression scenarios as much as possible. This will make testing more effective and less time-consuming. There are many automation tools available for mobile automation. For example — Appium, Calabash, Robotium, UIAutomator, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud-Based Automation Testing Solution for Mobile Testing
&lt;/h2&gt;

&lt;p&gt;Tools that use emulators or simulators for mobile testing are available in two categories- Cloud-based and on-premise. Cloud based tools are gaining popularity because of their ease of use and scalability.&lt;/p&gt;

&lt;p&gt;LambdaTest is a &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that offers both real device cloud and virtual platform testing using emulators and simulators.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of LambdaTest mobile app testing features:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4Y5WHjArZAM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;LambdaTest allows you to upload the app in a single click.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It offers both emulators/simulators and real devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can test your websites and webapps on mobile devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform &lt;a href="https://www.lambdatest.com/responsive-test-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;responsive test&lt;/a&gt; and compatibility test on different devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Completely eliminate the need for an on-premise device lab.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test fast and ship with confidence&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eliminate false positives&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrate with different communication and CICD tools&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test native app features and debug in real time using &lt;a href="https://www.lambdatest.com/full-page-screen-capture?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;full page screenshot&lt;/a&gt;, videos and logs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Perform both automated and manual testing&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Now, Automate &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=hashnode&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt; and perform browser automation testing with LambdaTest.Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Now perform free cross browser &amp;amp; &lt;a href="https://www.lambdatest.com/live-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;live testing&lt;/a&gt;. Mobile app testing is different from web application testing, and we have already addressed different scenarios that should be considered while testing mobile apps. It can be challenging to design an effective mobile testing strategy due to numerous devices. The app must ensure platform and &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug03_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;browser compatibility&lt;/a&gt;. I hope this blog helps you to create a mobile testing strategy effectively.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>testing</category>
      <category>mobile</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Top 9 Challenges In Automation Testing [2022]</title>
      <dc:creator>Ruchira Shukla</dc:creator>
      <pubDate>Tue, 02 Aug 2022 11:15:46 +0000</pubDate>
      <link>https://dev.to/testmuai/top-9-challenges-in-automation-testing-2022-46jd</link>
      <guid>https://dev.to/testmuai/top-9-challenges-in-automation-testing-2022-46jd</guid>
      <description>&lt;p&gt;&lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Automation Testing&lt;/a&gt; has become a necessity in the world of DevOps and Agile. Effective automation testing can be an awesome productivity booster for the testing team and an overall system quality enhancer in the long run. However, the most difficult element of starting with test automation is making sure it is used correctly.&lt;/p&gt;

&lt;p&gt;Those who have attempted to set up test automation will attest to the fact that it is not a cakewalk.&lt;br&gt;
As per the State of Test Automation 2020–2021 Survey by Kobiton, 25.9% of the organizations find choosing the right tool as the biggest challenge, followed by setting the right &lt;a href="https://www.lambdatest.com/blog/the-definitive-guide-to-automation-testing-for-it-teams/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation approach&lt;/a&gt;, and so on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4mv1a7wqrkmgkxhpvuy1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4mv1a7wqrkmgkxhpvuy1.png" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article on the automation testing challenges, we will discuss the top 9 key challenges in automation testing faced by developers and organizations and how to overcome the test automation challenges.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey! You can now test on &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium Automation Testing&lt;/a&gt; Grid Cloud of 3000+ Desktop &amp;amp; Mobile Browsers.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Why is automation testing important?
&lt;/h2&gt;

&lt;p&gt;The most important reason to utilize automated testing is to obtain a high-quality product with exceptional performance that offers several advantages. It results in a significant reduction in maintenance costs and a significant increase in software performance with faster Time to Market (TTM). In terms of budget, the importance of automation testing lies in charge reductions because the human is no longer required for anything other than the test’s maintenance. Automated testing aims to make testing as simple as feasible with scripts.&lt;/p&gt;

&lt;p&gt;If you are new to automation testing or want to migrate from manual testing to automation testing, this article on how to migrate from manual testing to automation testing will help you get started.&lt;/p&gt;

&lt;p&gt;From the below stats, test automation was cited by 42.5% of organizations as an important aspect of their quality assurance process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AyKjJXtgQtmxZqughLbgCMg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AyKjJXtgQtmxZqughLbgCMg.png" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Key challenges in automation testing
&lt;/h2&gt;

&lt;p&gt;An effective &lt;a href="https://www.lambdatest.com/blog/a-breakdown-of-continuous-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;continuous testing&lt;/a&gt; plan is one of the important components in a software development organization. Continuous testing necessitates the use of end-to-end automated testing, which allows for a better understanding of application quality early in the development cycle.&lt;/p&gt;

&lt;p&gt;It sounds fantastic, and it certainly is. However, as with any other development process, moving to an automated testing strategy frequently means dealing with common mistakes that can make this period unpleasant.&lt;/p&gt;

&lt;p&gt;What obstacles will a DevOps team face when attempting to execute a successful automated testing strategy? Let’s discuss them in detail.&lt;/p&gt;

&lt;p&gt;Run Selenium, Cypress, and Appium tests on LambdaTest to scale with the demand of your website and web apps.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/jrgx_3gfWVA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Finding the right framework and tool
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ASWvRxh8CWHtnEFGrCpzBCA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ASWvRxh8CWHtnEFGrCpzBCA.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finding the right automation tool is a very crucial challenge in automation testing for the success of automation. There are a lot of tools available, both licensed as well as open-source, which makes it difficult to choose. The choice of tool depends upon the kind of application and the extent of automation testing. Before selecting a particular tool, the test engineer should evaluate the pros and cons of each tool and consider based on the basis of the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ease of use&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scalability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintainability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integration with third-party tools like Github, Jira, Jenkins, Maven/Gradle, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No matter what testing methodology we use, if we do not have a tool that matches the business requirement, automation tends to fail eventually. There are several &lt;a href="https://www.lambdatest.com/blog/automation-testing-failure/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;top reasons for test automation failure&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A_jXuuhKhX0b1y-2Z9ZoPjg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A_jXuuhKhX0b1y-2Z9ZoPjg.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Researching tools and determining the best-suited one is a difficult task in and of itself. Likewise, this is a challenge in itself to research tools and find out the most appropriate one. Nevertheless, responses from the above stats indicate that &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt; is the preferred and one of the most &lt;a href="https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;popular test automation frameworks&lt;/a&gt; among all.&lt;/p&gt;

&lt;p&gt;A key part of this automation testing stack is the grid of devices used. Testing can never be comprehensive unless the tests are run on real devices to mimic real user conditions. Unfortunately, setting up a real device lab is expensive, cumbersome, and requires constant updations. Picking a &lt;a href="https://www.lambdatest.com/real-device-cloud?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;real device cloud&lt;/a&gt; could be a great option.&lt;/p&gt;

&lt;p&gt;Choosing the cloud-based infrastructure platforms like LambdaTest gives you access to more than 3000 real devices running on real operating systems to perform automation testing. In addition, this &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform allows users to test public or locally hosted web apps on various browsers, operating systems, and devices.&lt;/p&gt;

&lt;p&gt;LambdaTest provides developers and testers with a single integrated ecosystem in which they can securely perform all their tests. This can help you achieve higher levels of efficiency and &lt;a href="https://www.lambdatest.com/blog/code-coverage-vs-test-coverage/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test coverage&lt;/a&gt; while reducing the costs associated with setting up and maintaining test environments.&lt;/p&gt;

&lt;p&gt;This certification is for anyone who wants to stand out among Selenium automation testing professionals as they advance their careers.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the Selenium 101 certification from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qx9FPFfJm7E"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest videos around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress testing&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Execute &amp;amp; analyze Cypress test scripts online. Deploy quality builds faster with 40+ browser versions on &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress cloud&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Effective communication &amp;amp; collaboration in team
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AePGyY3cI5-uErWdlnEcOFg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AePGyY3cI5-uErWdlnEcOFg.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lack of communication and collaboration among the team is one of the key challenges in automation testing. Since automation testing requires significant investment and gives long-term ROI (Return On Investment) instead of instant gratification, its success is very much dependent on effective communication among all stakeholders.&lt;/p&gt;

&lt;p&gt;Wondering how to calculate your ROI? This article on &lt;a href="https://www.lambdatest.com/blog/how-do-you-calculate-your-roi-on-test-automation-with-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to calculate your ROI with test automation&lt;/a&gt; will help you make smart decisions.&lt;/p&gt;

&lt;p&gt;Business analysts, developers, and project managers should discuss the test cases that need to be automated and the necessary functionality. So planning a strategy that is in line with all the respective stakeholders is a challenge. Also, to get a green light from management on the strategic timeline, making necessary changes in the product is not an easy task.&lt;/p&gt;

&lt;p&gt;To overcome this, the automation team should try to make things transparent among all identified risks at the initial stage and communicate them as soon as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Identifying the test automation strategy
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AD69sXb9asUiGBI5p9CVkyg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AD69sXb9asUiGBI5p9CVkyg.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Without a proper test automation strategy, the efficiency of technology will be lost. This is like a body without a brain. Choosing the right strategy is another key challenge in automation testing that is instrumental in the success of automation and in showing business values. So what is a test automation strategy?&lt;/p&gt;

&lt;p&gt;Take a look at the below stats, where the majority of respondents stated that the primary strategic motivator for pursuing test automation was a desire to increase overall application quality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ADC0cmV7SxpjH0rxbWiydIw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ADC0cmV7SxpjH0rxbWiydIw.jpeg" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply putting a test automation strategy is a microcosm of the larger test strategy. Automation is a part of the overall testing process and should be considered thoughtfully. This is another obstacle or one of the key challenges in automation testing as test engineers would find it difficult to chalk out a plan with so many dimensions to consider.&lt;/p&gt;

&lt;p&gt;To deduce an effective strategy first, one should understand what is the need for strategy? A strategy should typically address the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What are the risks, capabilities, and functionalities, and how to inform the stakeholders, i.e., to arrive at a stable and repeatable communication process?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting our goals and plans.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conceptualize the overall thought process and proof of that concept.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auditing tool where you can go back and check your schedule and what has actually been done.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So ideally, to start a test automation strategy, one should take into account the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Define and identify high business value tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand your technology, tools, and resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Identify your risks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define your DevSecOps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider your testing environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider your test data management.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider agile tools.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Setting realistic expectations of automation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AqAHFxVIhcnOgtuYn9lsdbQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AqAHFxVIhcnOgtuYn9lsdbQ.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A lot has been said about test automation. But unfortunately, organizations tend to believe that automation would bring the magic that would solve all their issues which is not true.&lt;/p&gt;

&lt;p&gt;The expectations with test automation should be realistic and communicated clearly to higher management. In addition, what and how much should be automated to reap maximum benefit should be well documented. As already discussed, a well-defined automation strategy can play a vital role in setting up realistic expectations.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. High initial investment
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ApeOf2o1__GzbPkyM7iLebw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ApeOf2o1__GzbPkyM7iLebw.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Automation needs a high initial investment in terms of tools, skilled resources, infrastructure, etc. Sometimes it might require licensing costs on top of operational costs. Moreover, even for open-source tools like Selenium, one must take into account the cost incurred in training the resources and setting up the grid. This is a major challenge in automation testing as it is sometimes difficult to convince the management to invest in it.&lt;/p&gt;

&lt;p&gt;From the below stats, based on the overall quality assurance budget, the majority of organizations claimed that they spend between 30% and 49% of their overall QA budget on test automation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ae1EbGGrc04wLD_S-Js-1SA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ae1EbGGrc04wLD_S-Js-1SA.png" width="800" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To prove to the management that the financial benefits of automation are substantial, one should calculate the cost incurred in the production defects v/s cost involved in setting up automation.&lt;/p&gt;

&lt;p&gt;Don’t forget about the intangible benefits, such as the opportunity to update and adjust old workflows and procedures to boost efficiency by eliminating repetition or redistributing staff.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Inadequate testing infrastructure
&lt;/h2&gt;

&lt;p&gt;Another major challenge in automation testing is a lack of infrastructure to enable proper test coverage and execution speed. For example, consider the scenario in which an application must be tested on a variety of operating systems and browsers. It’s critical to execute test scripts in parallel to run tests against many configurations in an acceptable amount of time. And in order to achieve this, the testing infrastructure must be extremely robust in order to support &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While a company that is just getting started with test automation may not be well prepared to develop an internal testing infrastructure, there are other choices, such as a cloud-based testing infrastructure.&lt;/p&gt;

&lt;p&gt;LambdaTest provides a scalable infrastructure for startups and enterprises to fulfill their test automation needs. In addition, it eliminates the need to manage the in-house infrastructure so that the organizations can focus more on quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Problems with data reliance
&lt;/h2&gt;

&lt;p&gt;One of the most challenging aspects of test automation is data management. When the test script is executed, the data must be in a specific state; otherwise, it can cause serious issues in several scenarios. What happens, for example, if the test script is executed simultaneously in several test environments and configurations?&lt;/p&gt;

&lt;p&gt;Will it fail if the same data is used in multiple instances of the script? Any change to the data in one test execution instance can cause another instance to fail. What if the data of a script is built up by the execution of another test script?&lt;/p&gt;

&lt;p&gt;Developing self-contained and independent test scripts is the most effective technique to deal with these data management difficulties. All test scripts should be written in such a way that they create and clean all of the data needed for successful execution. In this case, the team must eliminate the possibility of test failure owing to data-related concerns.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Finding the right skills
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABSVHHJJtqPXvu49Ae1WggA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABSVHHJJtqPXvu49Ae1WggA.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From designing a test automation framework to writing test scripts, dilemma and coding skills are required. Most test automation tools are really only effective when manned by individuals who can design and maintain automation frameworks, build solutions, and test scripts accurately. They must also be able to deal with unexpected technical problems.&lt;/p&gt;

&lt;p&gt;Since automation frameworks differ in terms of features and operability, they must be familiar with the design and implementation protocols of the framework. Therefore, it would be wrong to assume that manual testers can work on automation tools or build a solution without proper training. However, investing in training and hiring new skilled resources is also challenging. It also demands time and is not feasible for organizations that want to scale up quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Stakeholders and end-users expectations
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A2Kt4ATgEFdt2mk-Wd6YSrw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A2Kt4ATgEFdt2mk-Wd6YSrw.jpeg" width="534" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No matter how good your tools or resources are, you must constantly keep in mind that testing cannot be done in a vacuum. It has one goal: to improve your product.&lt;/p&gt;

&lt;p&gt;While test automation is useful for checking for flaws automatically, humans are still required to finish the non-automated testing phases. And these tests provide plenty of useful data for making the best possible decisions when it comes to developing the system — not for the benefit of developers but the benefit of end-users.&lt;/p&gt;

&lt;p&gt;As a result, you must make certain that your testing team, management, and other stakeholders all agree on and understand the anticipated outcomes of your automation strategy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hey! Run your &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=aug02_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt; test scripts instantly on 50+ browser and OS combinations using the LambdaTest cloud. Execute Playwright Automation testing in parallel and cut down your test execution time by multiple folds.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Test automation is a continuous development and enhancement process. In this article on key challenges in automation testing, we have seen how by focusing more on fast value rather than fast tests, one can ensure the right approach to automation. Tests that run fast but miss the defects do not add any value. So the approach should be reducing the bugs in the production to reduce the costs that incur to resolve them at a later stage.&lt;/p&gt;

&lt;p&gt;Automation is challenging as well as expensive. But the result can be a better quality product in front of the customer and a faster release cycle.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>programming</category>
      <category>testing</category>
    </item>
    <item>
      <title>How To Use @RepeatedTest Annotation In JUnit 5</title>
      <dc:creator>Ruchira Shukla</dc:creator>
      <pubDate>Thu, 28 Jul 2022 10:32:00 +0000</pubDate>
      <link>https://dev.to/testmuai/how-to-use-repeatedtest-annotation-in-junit-5-3g7g</link>
      <guid>https://dev.to/testmuai/how-to-use-repeatedtest-annotation-in-junit-5-3g7g</guid>
      <description>&lt;p&gt;The JUnit framework is a popular &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework for unit testing in Java. The latest version of JUnit, i.e., JUnit 5 (also known as Jupiter), offers a number of improvements over JUnit 4. However, the community of JUnit users are often divided on this new release, with some favoring the stability of JUnit 4 and others preferring the new features being introduced with each release of JUnit 5. If you have been using JUnit 4, you can check the &lt;a href="https://www.lambdatest.com/blog/execute-junit4-tests-with-junit5/#JUnit5vsJUnit4?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit4 vs JUnit 5 comparison&lt;/a&gt; to understand the difference between them.&lt;/p&gt;

&lt;p&gt;While JUnit 5 has introduced a lot of new and useful annotations, @RepeatedTest in JUnit 5 is one of the most powerful &lt;a href="https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/" rel="noopener noreferrer"&gt;JUnit 5 annotations&lt;/a&gt; in the list. As an automation tester, we often get into a situation where we want to repeat a test case execution. If we have a flexible automation framework, we can pass such information through configuration in specific cases. Having said that, it is always good to have a feature that exclusively supports this requirement and can be instrumental while performing &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkpn5ahw9bm59t0ff8haw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkpn5ahw9bm59t0ff8haw.gif" width="500" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is RepeatedTest in JUnit 5?
&lt;/h2&gt;

&lt;p&gt;RepeatedTest, as the name suggests, is a test that is repeated during the test execution a certain no. of times. Let’s not confuse this with the &lt;a href="https://www.lambdatest.com/blog/junit-parameterized-test-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parameterized test in JUnit&lt;/a&gt;. A parameterized test repeatedly executes with different input data, while a repeated test repeatedly executes with the same input data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Are you looking for a &lt;a href="https://www.lambdatest.com/free-online-tools/decimal-to-gray-code?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Decimal to Gray Code&lt;/a&gt; covertor? It is a is a free online converter that converts any Decimal number base into gray code format.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the use of RepeatedTest ?
&lt;/h2&gt;

&lt;p&gt;As a QA engineer, the first question that comes to mind is “Why do we need to repeat a test multiple times?”. First, there can be many scenarios where we need to do so. For example, a specific link on a web page results in an environment error, but this error disappears after two clicks. This is a known issue and you do not want your test case to fail for such a known issue.&lt;/p&gt;

&lt;p&gt;Another scenario can be automating an application and clicking a link or navigating from one page to another. It always takes different load times, which sometimes results in timeout exceptions for the test case. In this case, we might want to execute the test case multiple times to get an average load time. And then pass that average load time as the threshold for the timeout.&lt;/p&gt;

&lt;p&gt;Basically, most of the time, repetition is required when there is some randomness in the test case.&lt;/p&gt;

&lt;p&gt;So, if you’re curious about the world of JUnit 5 annotations, this video will help you get started. You’ll learn JUnit 5 annotations in &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium&lt;/a&gt;, how to write a JUnit test with Selenium, how to execute JUnit tests on a cloud Selenium Grid, and much more.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/tpBX5w0I_Jo"&gt;
&lt;/iframe&gt;
&lt;br&gt;
However, you can follow the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with more such videos on the &lt;a href="https://www.youtube.com/playlist?list=PLZMWkkQEwOPn68qzCGJl07ZbnI7Ix5zKU" rel="noopener noreferrer"&gt;JUnit tutorial with Selenium&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to use JUnit 5 @RepeatedTest annotation
&lt;/h2&gt;

&lt;p&gt;JUnit Jupiter @RepeatedTest annotation is used to repeat the test case for specified no. of times. Each invocation of the test case behaves like a regular &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; method, so it has support for the same lifecycle callbacks and &lt;a href="https://www.lambdatest.com/blog/junit5-extensions/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;extensions in JUnit 5&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following example declares myTest() to repeat execution five times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@RepeatedTest](http://twitter.com/RepeatedTest)(5)
    void myTest() {
    // ...
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are certain rules associated with the method @RepeatedTest in JUnit 5.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The @RepeatedTest in JUnit 5 can not be private and static.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The return type for @RepeatedTest in JUnit 5 must be void.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s see how it is used in the test case with a basic example-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Case&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Launch the URL- &lt;a href="https://www.amazon.com/" rel="noopener noreferrer"&gt;https://www.amazon.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the navigation menu item- “BestSellers.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate that the page opened has the heading-“Amazon BestSellers.”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Repeat the same test case 5 times.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package Test;

    import java.net.MalformedURLException;
    import java.net.URL;

    import org.junit.After;
    import org.junit.Before;
    import org.junit.jupiter.api.AfterEach;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.RepeatedTest;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.junit.jupiter.api.Test;
    import junit.framework.Assert;

    public class RepeatedTestDemo {
       public WebDriver driver = null;

    [@BeforeEach](http://twitter.com/BeforeEach)
       public void setup() throws Exception {
           System.setProperty("webdriver.chrome.driver",
                   "DRIVER_EXE_PATH");
           driver = new ChromeDriver();
       }

    [@RepeatedTest](http://twitter.com/RepeatedTest)(value = 5)
       public void repeatedTestDemo() throws Exception {
           try {

               driver.get("[https://www.amazon.in/](https://www.amazon.in/)");
               driver.findElement(By.xpath("//a[text()='Best Sellers']")).click();
               String actual = driver.findElement(By.xpath("//div[[@id](http://twitter.com/id)='zg_banner_text']/div[1]")).getText();
               Assert.assertEquals("Pass", "Amazon Bestsellers", actual);
           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
       }

    [@AfterEach](http://twitter.com/AfterEach)
       public void tearDown() throws Exception {
           driver.quit(); // for illustration
       }

    }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Following is the output of the above code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AsWeW1JA_2Hg0OzNY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AsWeW1JA_2Hg0OzNY.png" width="681" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, by default, JUnit displays the repetition number along with the total number of repetitions. We can also modify the display name, which we will discuss later. For now, let us do a code walk-through.&lt;/p&gt;

&lt;p&gt;As it is quite evident that @RepeatedTest in JUnit 5 is treated as &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; annotation by JUnit 5, the lifecycle is also the same. For example, @BeforeEach and @AfterEach methods will be invoked before and after each invocation of the @RepeatedTest method in JUnit 5.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Are you looking for a &lt;a href="https://www.lambdatest.com/free-online-tools/decimal-to-bcd?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Decimal to BCD&lt;/a&gt; converter? In computing and electronic systems, a binary-coded decimal (BCD) is a method of representing each decimal digit by its binary sequence. The Decimal to BCD Converter converts an integer to a binary-coded decimal (BCD).&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to configure the custom test display name using @RepeatedTest annotation in JUnit 5
&lt;/h2&gt;

&lt;p&gt;@RepeatedTest in JUnit 5 supports DisplayName placeholder to give a custom display name to the test. It returns the value provided in the annotation @DisplayName for the test method. If there is no @DisplayName annotation given, it returns the method name itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @RepeatedTest(name={displayName})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The annotation supports two display name patterns.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;SHORT_DISPLAY_NAME&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LONG_DISPLAY_NAME&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;SHORT_DISPLAY_NAME&lt;/strong&gt; is the default placeholder. When used, JUnit displays the following pattern-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;repetition {currentRepetition} of {totalRepetitions}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;LONG_DISPLAY_NAME&lt;/strong&gt; when used, JUnit display the following pattern-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{displayName}:: repetition {currentRepetition} of {totalRepetitions}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the placeholders-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{currentRepetition}: is the current repetition count

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{totalRepetitions}: is the total number of repetitions

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Customized display names in JUnit 5
&lt;/h2&gt;

&lt;p&gt;We can also provide a string value and the supported placeholders to make it more meaningful. Let’s modify the above code to demonstrate the custom display name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package Test;

    import java.net.MalformedURLException;
    import java.net.URL;
    import org.junit.jupiter.api.AfterEach;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.DisplayName;
    import org.junit.jupiter.api.RepeatedTest;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class RepeatedTestDemo {
       public WebDriver driver = null;

    [@BeforeEach](http://twitter.com/BeforeEach)
       public void setup() throws Exception {
           System.setProperty("webdriver.chrome.driver",
                   "YOUR_DRIVER_EXE_PATH");
           driver = new ChromeDriver();
       }

    [@DisplayName](http://twitter.com/DisplayName)("Link Verification")
       [@RepeatedTest](http://twitter.com/RepeatedTest)(value = 3, name = "Testcase: {displayName} _ The current repetition count is  {currentRepetition} out of Total repetition count {totalRepetitions}")

    public void repeatedTestDemo() throws Exception {
           try {

    driver.get("[https://www.amazon.in/](https://www.amazon.in/)");
               driver.findElement(By.xpath("//a[text()='Best Sellers']")).click();
               String actual = driver.findElement(By.xpath("//div[[@id](http://twitter.com/id)='zg_banner_text']/div[1]")).getText();
               Assert.assertEquals("Pass", "Amazon Bestsellers", actual);
           } catch (Exception e) {
               System.out.println(e.getMessage());
           }
       }

    [@AfterEach](http://twitter.com/AfterEach)
       public void tearDown() throws Exception {
           driver.quit(); // for illustration
       }

    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the displayName is passed as a parameter, and it would replace the value of @displayName annotation at the run time. Therefore, the output of the above code would be something as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2436%2F0%2Ah0_XtceLKfuXXV5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2436%2F0%2Ah0_XtceLKfuXXV5c.png" width="800" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ATer3A9Trx1z226YV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ATer3A9Trx1z226YV.png" width="800" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium &lt;a href="https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automation testing with JUnit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the JUnit certification from LambdaTest:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fWsCwrtElAw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use RepeatedTest: RepetitionInfo Interface in JUnit 5
&lt;/h2&gt;

&lt;p&gt;RepetitionInfo interface defines methods to retrieve the information about the current repetition and the total no. of repetitions. Here’s how we can use it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RepetitionInfo.getCurrentRepetition()&lt;/strong&gt; returns current repetition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RepetitionInfo.getTotalRepetitions()&lt;/strong&gt; returns total no. of repetitions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Here is A Definitive Guide To &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Regression Testing&lt;/a&gt;. Do Check it out.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use RepeatedTest : RepeatedTest Interface in JUnit 5
&lt;/h2&gt;

&lt;p&gt;RepeatedTest interface defines methods to get attributes of the annotation @RepeatedTest of the test method. Here’s how we can use it-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RepeatedTest.name()&lt;/strong&gt; returns the name value passed as a parameter in @RepeatedTest Annotation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;RepeatedTest.name()&lt;/strong&gt; returns the name value passed as a parameter in @RepeatedTest Annotation.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;However, the best way to harness the real potential of the JUnit framework for test automation is to shift it from a local Selenium Grid to a cloud-based Selenium Grid so that it can be executed in any browser anywhere in the world. When combined with LambdaTest, the JUnit framework allows developers to execute automated acceptance tests on a &lt;a href="https://www.lambdatest.com/selenium-automation" rel="noopener noreferrer"&gt;cloud Selenium Grid&lt;/a&gt;, which provides true remote testing capabilities.&lt;/p&gt;

&lt;p&gt;LambdaTest is a cloud-based automated &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; platform that allows you to easily run Selenium tests on more than 3,000 real browsers and operating systems in the cloud. You can run tests on any &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browser&lt;/a&gt; or operating system with just one command, or create powerful suites that contain thousands of your own custom-built test steps.&lt;/p&gt;

&lt;p&gt;Selenium-Jupiter allows you to run Selenium tests against a Grid of Remote Web Browsers (RWB) on different browser and platform combinations. LambdaTest helps you run &lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul28_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing in Selenium&lt;/a&gt; with increased efficiency and speed, by making use of cloud-based automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this Selenium JUnit 5 tutorial, we have covered the annotation @RepeatedTest in JUnit 5 along with its use case. As we discussed, the annotation is particularly useful when we want to ascertain a scenario. In addition, the advantage of having an exclusive functionality for such a case is wonderful. So, what’s your use case for this annotation? Let us discuss this in the comments.&lt;/p&gt;

&lt;p&gt;Happy Testing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>TestNG vs JUnit: Which testing framework should you choose?</title>
      <dc:creator>Ruchira Shukla</dc:creator>
      <pubDate>Wed, 27 Jul 2022 13:21:00 +0000</pubDate>
      <link>https://dev.to/testmuai/testng-vs-junit-which-testing-framework-should-you-choose-55e</link>
      <guid>https://dev.to/testmuai/testng-vs-junit-which-testing-framework-should-you-choose-55e</guid>
      <description>&lt;p&gt;A test automation framework is a set of components that facilitates the execution of tests along with reporting the results of the test execution. However, the discovery of the right &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;test automation&lt;/a&gt; framework can be super-challenging since there are so many options at your perusal. Picture this — When performing &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium &lt;/a&gt;using Java, you have to choose from a gruelling list of &lt;a href="https://www.lambdatest.com/blog/top-10-java-testing-frameworks/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;10 Java testing frameworks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AqGeZ2GFF8tj-Xr_H.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AqGeZ2GFF8tj-Xr_H.png" width="364" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As far as test automation frameworks in Selenium Java are concerned, JUnit and TestNG are preferred in comparison to the other frameworks in the list. Some of the pertinent questions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How does JUnit stack up against TestNG in the TestNG vs JUnit comparison?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is it possible to run JUnit tests with TestNG (and vice-versa)?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What annotations are present in JUnit and TestNG?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A side-by-side comparison of TestNG vs JUnit will give a clear indication of how the two prominent test automation frameworks stack up against each other. Unearthing the difference between JUnit and TestNG frameworks in &lt;a href="https://www.lambdatest.com/blog/selenium-webdriver-tutorial-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium WebDriver&lt;/a&gt; will help in deciding the best-suited framework for automation tests.&lt;/p&gt;

&lt;p&gt;In this blog, we do a thorough TestNG vs JUnit comparison — learnings of which will help in arriving at a wise decision for choosing the ideal test automation framework for your project. In this TestNG vs JUnit comparison, we have used JUnit 5 (the latest version of the JUnit framework) for showcasing example implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to JUnit &amp;amp;TestNG Test Automation Frameworks
&lt;/h2&gt;

&lt;p&gt;Before we get started with the TestNG vs JUnit comparison, let’s look at some of the basic essentials of the two frameworks. JUnit is an open-source unit testing framework for Java that was first introduced in 1997. At the time of writing this blog, JUnit 5 is the latest version of the JUnit framework. As the Selenium framework supports Java; many QA engineers prefer using the JUnit framework for web automation testing. In case you are getting started with JUnit, you could check out our earlier blog that helps in &lt;a href="https://www.lambdatest.com/blog/setup-junit-environment/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;setting up JUnit Environment for the first test&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TestNG&lt;/strong&gt; is also a popular open-source testing framework for Java. TestNG was created in 2007 with a goal to cover a wider range of test categories — Unit Testing, Functional Testing, &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=sep13_kj&amp;amp;utm_term=kj&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;End-To-End Testing&lt;/a&gt;, Integration Testing, and more. As of writing this blog, the latest version of TestNG is 7.3.0. You can check out our introductory blog on &lt;a href="https://www.lambdatest.com/blog/create-testng-project-in-eclipse-run-selenium-test-script/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to create a TestNG project in Eclipse&lt;/a&gt; for realizing web automation testing with TestNG.&lt;/p&gt;

&lt;p&gt;It is necessary to know the difference between JUnit and TestNG so that you can make an informed decision when it comes to choosing the ideal test automation framework. This is the primary reason why we came up with a head-on TestNG vs JUnit comparison.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Did you know? JSON is a common format for storing data, but it can be hard to read. &lt;a href="https://www.lambdatest.com/free-online-tools/json-prettify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Prettify JSON&lt;/a&gt; will indent the JSON file, make sure stuff is lined up in a similar manner, and will put closing parenthesis in the same space every time.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TestNG vs JUnit — Comparison of the best test automation frameworks
&lt;/h2&gt;

&lt;p&gt;Both TestNG and JUnit are amongst the &lt;a href="https://www.lambdatest.com/blog/9-of-the-best-java-testing-frameworks-for-2021/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;top automation frameworks in Java&lt;/a&gt;. Though they are hugely popular, the fact is that both frameworks have their own share of pros and cons. We would keep this discussion for a later blog since the TestNG vs JUnit can be a good reference to choose the framework for your automation project.&lt;/p&gt;

&lt;p&gt;For the TestNG vs JUnit comparison, we have made use of the JUnit 5 (latest version of JUnit framework) instead of JUnit 4 framework. If you are still using the JUnit 4 framework with Selenium WebDriver, you can still &lt;a href="https://www.lambdatest.com/blog/execute-junit4-tests-with-junit5/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;execute JUnit 4 tests with JUnit 5&lt;/a&gt; framework.&lt;/p&gt;

&lt;p&gt;Shown below is the detailed difference between JUnit and TestNG frameworks in Selenium WebDriver:&lt;/p&gt;

&lt;p&gt;Watch this video to learn how TestNG has become one of the most robust test automation frameworks and all you need to know to get started with TestNG in Selenium.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/90F7dePW1vo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Suites in JUnit and TestNG
&lt;/h2&gt;

&lt;p&gt;For starters, a test suite is a collection of test cases that lets you run the test cases simultaneously. It’s a logical grouping that can be treated as a single pack while execution.&lt;/p&gt;

&lt;p&gt;JUnit 5 was re-designed to overcome the limitations of the previous JUnit versions (including JUnit 4). The concept of test suites was introduced in JUnit 5 since Junit 4 (and earlier versions of JUnit) did not provide the feature to create test suites.&lt;/p&gt;

&lt;p&gt;Test suites in JUnit 5 are realized using the @ RunWith and @ Suite classes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@RunWith](http://twitter.com/RunWith)(Suite.class)

    [@Suite](http://twitter.com/Suite).SuiteClasses({
       JUnitTestSuiteDemo1.class,
        JUnitTestSuitDemo2.class
    })

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In TestNG, the test suite is defined in an xml file (e.g. testng.xml) The suite tag is defined in the file as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)" &amp;gt;
&amp;lt;suite name="DemoTestSuite"&amp;gt;
  &amp;lt;test name="DemoTest" &amp;gt;
    &amp;lt;classes&amp;gt;
       &amp;lt;class name="demo.demo.TestSuiteDemo/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With TestNG certification, you can challenge your skills in performing automated testing with TestNG and take your career to the next level.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the TestNG certification from LambdaTest:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dzXX2hJhuCY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Annotations in JUnit and TestNG
&lt;/h2&gt;

&lt;p&gt;Annotations in the test automation framework provide additional information about the class or the test method. For a quick recap, check out our detailed guide on &lt;a href="https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;TestNG annotations for Selenium automation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Support for annotation can be considered as one of the vital points of TestNG vs JUnit comparison. Both JUnit and TestNG are annotation-based frameworks.&lt;/p&gt;

&lt;p&gt;Most of the annotations in TestNG and JUnit offer the same functionality with a slight change in the naming nomenclature. The difference between JUnit and TestNG from an annotation standpoint is that TestNG has some additional annotations in comparison to JUnit.&lt;/p&gt;

&lt;p&gt;Here is the TestNG vs JUnit comparison as far as annotations are concerned:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;SCRIPTION&lt;/th&gt;
&lt;th&gt;TESTNG&lt;/th&gt;
&lt;th&gt;JUNIT 5&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Marks the method as test method&lt;/td&gt;
&lt;td&gt;@ Test&lt;/td&gt;
&lt;td&gt;@ Test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed before the first test method of the class&lt;/td&gt;
&lt;td&gt;@ BeforeClass&lt;/td&gt;
&lt;td&gt;@ BeforeAll&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed after all the test methods of the current class have been executed.&lt;/td&gt;
&lt;td&gt;@ AfterClass&lt;/td&gt;
&lt;td&gt;@ AfterAll&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed before each test method&lt;/td&gt;
&lt;td&gt;@ BeforeMethod&lt;/td&gt;
&lt;td&gt;@ BeforeEach&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed after each test method&lt;/td&gt;
&lt;td&gt;@ AfterMethod&lt;/td&gt;
&lt;td&gt;@AfterEach&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed before the suit.&lt;/td&gt;
&lt;td&gt;@ BeforeSuite&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed after suit.&lt;/td&gt;
&lt;td&gt;@ AfterSuite&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed before the test.&lt;/td&gt;
&lt;td&gt;@ BeforeTest&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed before the test.&lt;/td&gt;
&lt;td&gt;@ AfterTest&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed before the first test method of any of these groups.&lt;/td&gt;
&lt;td&gt;@ BeforeGroups&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The annotated method is executed after the first test method of any of these groups.&lt;/td&gt;
&lt;td&gt;@ AfterGroups&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ignore Test&lt;/td&gt;
&lt;td&gt;@ Test(Enable=false)&lt;/td&gt;
&lt;td&gt;@ Disabled (In JUnit4 it is @ignore)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Expected exception&lt;/td&gt;
&lt;td&gt;@ Test(expectedException=Arithmetic&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exception.class)&lt;/td&gt;
&lt;td&gt;
&lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt;(expected=Arithmetic&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exception.class)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timeout&lt;/td&gt;
&lt;td&gt;@ Test(timeout = 1000)&lt;/td&gt;
&lt;td&gt;@ Timeout&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Check out our earlier blog on &lt;a href="https://www.lambdatest.com/blog/tutorial-on-junit-annotations-in-selenium-with-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;JUnit Annotations in Selenium WebDriver&lt;/a&gt; to get detailed insights on annotations in the said framework.&lt;/p&gt;

&lt;p&gt;Watch this video to learn about the TestNG Annotations and how they help provide better structure and readability to the code.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/dzXX2hJhuCY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  TestNG vs JUnit: Test case Management in TestNG and JUnit frameworks
&lt;/h2&gt;

&lt;p&gt;Managing test case execution is a lot easier in TestNG in comparison to JUnit. In TestNG, QA engineers can group tests, ignore tests, parameterize tests, and write dependent tests in an efficient manner.&lt;/p&gt;

&lt;p&gt;Let’s look at each of those points in this section of TestNG vs JUnit comparison:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grouping Test Cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In TestNG, you can group the test cases by simply providing parameters in the @ Test annotation as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @Test(groups={“groupname1”,&amp;lt;”group2"&amp;gt;..,&amp;lt;”groupN”&amp;gt;})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can check out our detailed blog on &lt;a href="https://www.lambdatest.com/blog/grouping-test-cases-in-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to group test cases in TestNG&lt;/a&gt; for more information on grouping tests in TestNG. The particular group(s) can be executed by providing the name(s) in the XML file under  and  tags as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;suite name="MyTestSuite"&amp;gt;  
  &amp;lt;groups&amp;gt;  
     &amp;lt;run&amp;gt;  
        &amp;lt;include name="Dashboard"/&amp;gt;  
     &amp;lt;/run&amp;gt;  
  &amp;lt;/groups&amp;gt;  
 &amp;lt;test name="LoginTest"&amp;gt;  
    &amp;lt;classes&amp;gt;  
        &amp;lt;class name="CheckUserLogin"/&amp;gt;  
        &amp;lt;/classes&amp;gt;  
    &amp;lt;/test&amp;gt;  
    &amp;lt;test name="UserHomePageTest"&amp;gt;  
   &amp;lt;classes&amp;gt;  
      &amp;lt;class name="CheckUserHomePage"/&amp;gt;  
   &amp;lt;/classes&amp;gt;  
   &amp;lt;/test&amp;gt;  
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, the tests under group “Dashboard” will be executed. JUnit does not provide a straightforward way for grouping the test cases.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ignore Test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are scenarios where you might need to run a select set of tests from a huge test suite. The test cases that need not be executed have to be ignored. Ignoring tests in JUnit and TestNG is specifically useful when only a particular feature has to be tested.&lt;/p&gt;

&lt;p&gt;TestNG and JUnit automation frameworks provide the feature where tests can be ignored. In TestNG, we can provide a parameter in @ Test annotation as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Test](http://twitter.com/Test)(enabled=false)
    public void TestIgnoreDemo()
    {  
        /* Implementation goes here */
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Junit 5, the @ ignore annotation is used for ignoring test cases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Ignore](http://twitter.com/Ignore)
    public void TestIgnoreDemo()
    {
        /* Implementation goes here */
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Parameterization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Parameterization in the test suite lets you run a certain test against different input values. Improved code reusability and readability are the major benefits of parameterization in automation testing. Parameterization can turn out to be a make or break deal in the TestNG vs JUnit comparison.&lt;/p&gt;

&lt;p&gt;In TestNG, passing parameters to a testcase is straightforward. It uses @ Parameter annotation with the parameter to the given test method. The @ Parameters annotation should be used in case you want to pass more than one parameter to the method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class Demo {
        [@Test](http://twitter.com/Test)
        [@Parameters](http://twitter.com/Parameters)({"browser"})
        public void demoTest(String browser)
        {
            System.out.println("The browser Is : " + browser);
        }
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of variable ‘browser’ is declared in the xml file (e.g. testng.xml) as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;suite name="ParameterizedDemo"&amp;gt;
      &amp;lt;test name="test1"&amp;gt;
          &amp;lt;parameter name="browser" value="chrome"/&amp;gt;
          &amp;lt;parameter name="browser" value="IE"/&amp;gt;
          &amp;lt;classes&amp;gt;
              &amp;lt;class name="Demo" /&amp;gt;
          &amp;lt;/classes&amp;gt;
      &amp;lt;/test&amp;gt;
    &amp;lt;/suite&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s not all. &lt;a href="https://www.lambdatest.com/blog/parameterization-in-testng-dataprovider-and-testng-xml-examples/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Data Providers in TestNG&lt;/a&gt; can also be used for realizing parameterized tests in TestNG.&lt;/p&gt;

&lt;p&gt;In JUnit, parameter(s) can be passed using the @ParameterizedTest annotation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@ParamerizedTest](http://twitter.com/ParamerizedTest)
    [@ValueSource](http://twitter.com/ValueSource)(strings = { "Chrome", "IE", "Safari" })
    void DemoParameterize(String browser) {
        void  setBrowser("The browser is:"+browser));
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On executing the above code, the test DemoParameterize will be triggered separately with the input parameters as Chrome, IE, and Safari. You can check out our detailed blog on &lt;a href="https://www.lambdatest.com/blog/junit-parameterized-test-selenium/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Parameterization in JUnit with Selenium Driver&lt;/a&gt; to gather insights on how to use parameterized tests in JUnit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dependent Test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Autonomous test design is considered as one of the &lt;a href="https://www.lambdatest.com/blog/selenium-best-practices-for-web-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;best practices for Selenium test automation&lt;/a&gt;. However, there are cases where dependency between automation tests cannot be avoided at any cost. Test dependency refers to the ability of one test being dependent on another test method.&lt;/p&gt;

&lt;p&gt;In TestNG, Dependent methods can be defined with the help of @ DependsOnMethods annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class DependentDemo {

        [@Test](http://twitter.com/Test) (dependsOnMethods = { "Launcher" })
        public void login() {
            System.out.println("Login to the portal");
        }

        [@Test](http://twitter.com/Test)
        public void Launcher() {
            System.out.println("Launch the application");
        }
      }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the test method login() is dependent on the Launcher() method. Here is the execution output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A79fB4rK0FTL82p-J.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A79fB4rK0FTL82p-J.png" width="455" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JUnit does not support method dependency, hence TestNG scores a brownie point in the test dependency TestNG vs JUnit comparison 🙂&lt;/p&gt;

&lt;p&gt;This JUnit certification establishes testing standards for those who wish to advance their careers in Selenium automation testing with JUnit.&lt;/p&gt;

&lt;p&gt;Here’s a short glimpse of the JUnit certification from LambdaTest:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fWsCwrtElAw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exception Handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Exception handling in web automation testing refers to the ability of a test method to throw an exception when it encounters an error during the execution phase. Both JUnit and TestNG frameworks have support for exception handling.&lt;/p&gt;

&lt;p&gt;In TestNG, exceptions are handled using the expectedException parameter in @ Test annotation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Test](http://twitter.com/Test)(expectedExceptions = ArithmeticException.class)
    public void DivideByZero() {
      int i = 10/0;
    }In JUnit 5, the assertThrows API is used for throwing an exception

    [@Test](http://twitter.com/Test)
    public void whenDividerIsZero_thenDivideByZeroExceptionIsThrown() {
        Calculator calculator = new Calculator();
        assertThrows(DivideByZeroException.class, () -&amp;gt; calculator.divide(10, 0));
    }Timeouts


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Timeout in tests means that the tests should fail if they take longer than expected time for executing a test. This is a critical feature in web automation testing as an alarm is raised if the tests are not executed within a stipulated time period.&lt;/p&gt;

&lt;p&gt;In TestNG, the timeout parameter which specifies the maximum execution time is added to the @ Test annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Test](http://twitter.com/Test)(timeOut = 1000)
    public void timeoutDemo() {
        while (true);
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how timeouts in Selenium are handled in the JUnit 5 framework:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@Test](http://twitter.com/Test)
    public void timeoutDemo() throws InterruptedException {
        Assertions.assertTimeout(Duration.ofMillis(1000), () -&amp;gt; Thread.sleep(10000));
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Customization of Test Names&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is no way to customize test names in the TestNG framework. In JUnit 5, we can provide a customized name to the tests with the help of @ DisplayName annotation. The same is shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [@ParameterizedTest](http://twitter.com/ParameterizedTest)
    [@ValueSource](http://twitter.com/ValueSource)(strings = { "Hello", "World" })
    [@DisplayName](http://twitter.com/DisplayName)("Test Method to check that the inputs are not nullable")
    void givenString_TestNullOrNot(String word) {
        assertNotNull(word);
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are looking for customized test names, JUnit should be the go-to test automation framework.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nesting of Test Cases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The @ Nested annotation in JUnit Jupiter can be used to mark nested classes that have to be included in test case execution. @ Nested tests give the QA engineer more capabilities to express the relationship among several groups of tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public class MyApp
    {
        [@BeforeAll](http://twitter.com/BeforeAll)
        static void launchMyApp()
        {
            //the code to launch MyApp
        }
        [@Test](http://twitter.com/Test)
        [@DisplayName](http://twitter.com/DisplayName)(“Testcase to create new user”)
        void signUp()
        {
            //the code to create new user 
        }

        [@Nested](http://twitter.com/Nested)
        [@DisplayName](http://twitter.com/DisplayName)(value=“Nested class for Login to MyApp”)
        class login
        {
            void verifyUser()
            {
                //the code to validate the user
            }
            void verifyNotNull()
            {
                //code to validate that username and password fields are not Null
            }
        }
        [@AfterAll](http://twitter.com/AfterAll)
        static void closeMyApp()
        {
            //the code to close MyApp
            //releasing all used objects goes here
        }
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/grouping-test-cases-in-testng/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Grouping tests in TestNG&lt;/a&gt; is a common way for realizing nested tests in TestNG. As far as nested tests are concerned, TestNG scores high in the TestNG vs JUnit battle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Did you know? &lt;a href="https://www.lambdatest.com/free-online-tools/json-minify?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=free_tools" rel="noopener noreferrer"&gt;Minify JSON&lt;/a&gt; is a JavaScript library that removes whitespace and comments from blocks of JSON-like content, while preserving its syntax.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Parallel Test Execution in TestNG and JUnit frameworks
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.lambdatest.com/blog/what-is-parallel-testing-and-why-to-adopt-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Parallel testing in Selenium&lt;/a&gt; is one of the preferred ways to perform tests in parallel across different input combinations. Using a cloud-based Selenium Grid instead of a local Selenium Grid helps to achieve more from parallelism offered by the respective framework.&lt;/p&gt;

&lt;p&gt;Both TestNG and JUnit frameworks support parallel test execution. In testNG, testers can assign the thread count in xml file (e.g. testng.xml) and run the tests parallely as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE suite SYSTEM "[http://testng.org/testng-1.0.dtd](http://testng.org/testng-1.0.dtd)" &amp;gt;
&amp;lt;suite name="DemoTestSuite"&amp;gt;
  &amp;lt;test name="DemoTest"  parallel="methods" thread-count="2"&amp;gt;
    &amp;lt;classes&amp;gt;
       &amp;lt;class name="demo.demo.TestSuiteDemo/&amp;gt;
    &amp;lt;/classes&amp;gt;
  &amp;lt;/test&amp;gt;
&amp;lt;/suite&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our blog on &lt;a href="https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/#ParallelTesting?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;parallel testing in JUnit&lt;/a&gt; is a good resource to gain insights on how to practically use parallelism in JUnit for Selenium automation testing. In testNG, parallel execution can be achieved at method, test, class, and instance levels.&lt;/p&gt;

&lt;p&gt;Parallel test execution in JUnit was introduced in JUnit 5, however it is still in the experimental mode. Here are some ways in which parallel testing can be achieved with JUnit 5:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;junit.jupiter.parallel.process = true&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;junit.jupiter.execution.parallelism = true&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;junit.jupiter.execution.parallel.enabled = true&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;junit.jupiter. execution = “parallel”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The value for junit.jupiter.execution.parallel.enabled configuration can be set by providing necessary parameters in the Maven Surefire plugin. Alternatively, you can also set the parameter in unit-platform.properties or by providing system properties to JVM.&lt;/p&gt;

&lt;p&gt;This is how the difference between JUnitand TestNG pans out when evaluated on parameters like test execution, parallelism, parameterization, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do check out &lt;a href="https://www.lambdatest.com/android-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Android Emulator&lt;/a&gt; Online- Test your web and mobile apps on Android Emulators online. Ensure your apps are compatible across latest and legacy Android operating systems, devices, and browsers. Start Testing Now !!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Parallel Test Execution using TestNG on LambdaTest Grid
&lt;/h2&gt;

&lt;p&gt;The true potential offered by parallel testing in JUnit and TestNG can be harnessed by running the tests on a cloud-based Selenium Grid (instead of a local Selenium Grid). There are numerous benefits offered by &lt;a href="https://www.lambdatest.com/blog/cloud-selenium-testing/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing on the cloud&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For demonstration of parallel testing, we will use the cloud-based Selenium Grid by LambdaTest. LambdaTest offers both &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-junit?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Automation testing with JUnit&lt;/a&gt; and &lt;a href="https://www.lambdatest.com/selenium-automation-testing-with-testng?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium Automation testing with TestNG&lt;/a&gt; frameworks. The browser capabilities are generated using the &lt;a href="https://www.lambdatest.com/capabilities-generator/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Lambda Test capability generator&lt;/a&gt;. The combination of username and access key is used to access the LambdaTest Grid.&lt;/p&gt;

&lt;p&gt;Here are the two test cases used for the demonstration of parallel testing with TestNG:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TestCase — 1&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to Selenium Playground Simple Form Demo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the message in the text field&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Show Message button&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify the message on the right panel&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;TestCase — 2&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to the Selenium Playground Simple Form Demo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the value of a in the first textbox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the value of b in the second textbox.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the Get Total button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify the sum on the right panel.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation (using TestNG Framework)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    package Test; 
    import static org.testng.Assert.assertTrue;

    import java.net.MalformedURLException;
    import java.net.URL;
    import org.openqa.selenium.By;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;

    public class Lambdatest {
        public RemoteWebDriver driver = null;
        public static String username = "user-name";
        public static String accessKey = "access-key";
        @BeforeClass

        public void setup() throws Exception {

            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("platform", "Windows 10");
            capabilities.setCapability("browserName", "Chrome");
             capabilities.setCapability("version", "88.0");
                capabilities.setCapability("resolution","1024x768");
                capabilities.setCapability("build", "Lambdatest");
                capabilities.setCapability("name", "Lambdatest");
                capabilities.setCapability("network", true); // To enable network logs
                capabilities.setCapability("visual", true); // To enable step by step screenshot
                capabilities.setCapability("console", true);
            capabilities.setCapability("user", username);
            capabilities.setCapability("accesskey", accessKey);
            try {       
                driver= new RemoteWebDriver(new URL("https://"+username+":"+accessKey+"@hub.lambdatest.com/wd/hub"), capabilities);            
            } catch (MalformedURLException e) {
                System.out.println("Invalid grid URL");
            }
        }

        @Test
        public void testAddition() throws Exception {
                    try {
                        driver.get("");
                        driver.findElement(By.id("sum1")).clear();
                        driver.findElement(By.id("sum1")).sendKeys("100");
                        driver.findElement(By.id("sum2")).clear();
                        driver.findElement(By.id("sum2")).sendKeys("200");    
                        driver.findElement(By.className("btn btn-dark selenium_btn")).click();
                        String strResult=driver.findElement(By.id("addmessage")).getText();
                        assertTrue(strResult.equals("300"),"Pass");
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
        }
        @Test
        public void testUserMessage() throws Exception {
                    try {
                        String strMessage="Hello! Welcome to the Lambda Test";
                        String actualMsg="";
                        driver.get("");
                        driver.findElement(By.id("user-message")).clear();
                        driver.findElement(By.id("user-message")).sendKeys(strMessage);
                        driver.findElement(By.id("showInput")).click();    
                        actualMsg=driver.findElement(By.id("message")).getText();
                        assertTrue(actualMsg.equals(strMessage),"Pass") ;

                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
        }
        @AfterClass
        public void tearDown() throws Exception{
            driver.quit();
        }
    }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the execution snapshot from LambdaTest:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2Aeg423HWWPCv2H1fg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2048%2F0%2Aeg423HWWPCv2H1fg.png" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LambdaTest also provides the video recording of the test case execution&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A8tE7vuz_DcdRT9oR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A8tE7vuz_DcdRT9oR.png" width="512" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have not covered parallel testing with JUnit 5 here since, the feature is still in the experimental mode. In case you are using JUnit 4, do check out &lt;a href="https://www.lambdatest.com/blog/automated-testing-with-junit-and-selenium-for-browser-compatibility/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=jul27_sb&amp;amp;utm_term=sb&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;how to perform parallel testing with JUnit 4 and Selenium&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ArfkOAymY2FgahjXU" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2ArfkOAymY2FgahjXU" width="498" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While JUnit 4 has several limitations in test case management, JUnit 5 tried to overcome those and also added new features in the process. Though there is a difference between JUnit and TestNG as far as annotations are concerned, the point is that both the frameworks are equally capable for usage in Selenium automation testing.&lt;/p&gt;

&lt;p&gt;We have to wait and watch how JUnit 5 (and the subsequent versions of JUnit) evolve over a period of time. Overall, there is a thin line of difference between JUnit and TestNG and the choice for the test automation framework purely depends on the requirements of the project.&lt;/p&gt;

&lt;p&gt;In the TestNG vs JUnit battle, my overall vote would go for TestNG since parallel testing in Selenium can be achieved with ease using the TestNG framework.&lt;/p&gt;

&lt;p&gt;Irrespective of whether you choose JUnit or TestNG, the true potential of the corresponding framework can only be exploited by running the tests on a cloud-based Selenium Grid like LambdaTest. The major reason being parallel tests can be executed on different browser and OS combinations at blazing fast speeds.&lt;/p&gt;

&lt;p&gt;Which framework do you prefer in the TestNG vs JUnit battle? Do leave your reasons in the comments section of this blog…&lt;/p&gt;

&lt;p&gt;Happy Testing 🙂&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
