TestNG and Cucumber (Configuration,execution and simple comparison):

What is TestNG

Step 1:

  1. Install Eclipse IDE from eclipse website.
  2. Once Eclipse installed, go to help and navigate to Market Place.
  3. Look for TestNG for Eclipse.
  4. Click the install button.
  5. Once the installation done,restart the Eclipse.
  6. To verify Check by right clicking on a project name and Try changing it to the TestNG class.

Step 2:

  • Create a Java Project
  • Add TestNG libraries to the project by navigating to the library tab.
  • Create the TestNG class in the src folder with TestNG annotations.

Step3:

  1. Test annotations are tags that describes about method,class and suite. It is where we explain the execution approach of the test cases and features associated to it.
  2. To include annotations in the selenium code,we need to import testng annotations with the package
  • @BeforeMethod and @AfterMethod — These annotations run before and after each test method
  • @BeforeClass and @AfterClass — These annotations run once before and after the first @test method in a class
  • @BeforeTest and @AfterTest — The BeforeTest annotation runs before the @BeforeClass.
  • @AfterTest annotation runs after the @AfterClass annotation.
  • @BeforeSuite and @AfterSuite– These annotations run before and after any test annotated method in a class respectively. These annotations start the beginning of a test and the end of it, for all the classes in a suite

Step 4:

  • TestNG output will be on two windows — 1) Console Window

What is Cucumber:

  1. For configuring the cucumber the jar files are added to the project which can be dowloaded.
  2. Add the required cucumber Maven dependencies from Maven repository and add it to the pom.xml
Cucumber executing process
  1. Feature files — Code is written in simple english(Gherkin language)
  2. Step definition- Has the actual code.
  3. Runner file — Code written here to execute the project which includes feature file and step definition file.

Step 3: Runner File:

Comparison:

  1. TestNG used in Unit Testing,Integration Testing, End-to-End Testing where Cucumber is used in Acceptance Testing.
  2. TestNG is a Testing Framework for Java Programming language where Cucumber Testing tool for Behaviour- driven-development.
  3. In TestNG multiple test cases can be used in single XML file with defining priorities which test cases need to be executed first. In Cucumber use of tag Cucumber feature files or individual tests to group tests.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store