Working with TestNG - Starters Guide
Chapters
Working with Dependencies in test cases
Sometimes,we may need to invoke method in a test case in particular order or we want to share data and state between between methods.
TestNG allows to specify dependencies based on :
- Using attributes dependsOnMethods in @Test annotations or
- Using attributes dependsOnGroups in @Test annotations
Create a Class:
Create a class named as DependentExample.java
package testNG; import org.testng.annotations.Test; public class DependentExample { @Test(dependsOnMethods = { "openBrowser" }) public void signIn() { System.out.println("Inside signIn()"); } @Test public void openBrowser() { System.out.println("Inside openBrowser()"); } @Test(dependsOnMethods = { "signIn" }) public void logOut() { System.out.println("Inside logOut()"); } }
Create testing.xml file as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<suite name="test Suite">
<test name="Exception Example">
<classes>
<class name="testNG.DependentExample"/>
</classes>
</test>
</suite>
Run the testing.xml file by click on run button in eclipse.
The Output is shown below:
Description
This tutorial is focused on getting you started on TestNG, the testing framework inspired from JUnit and NUnit. Here is a quick table of contents
- What is TestNG?
- Environment Set-up
- Writing Tests
- Basic Annotations
- Execution Procedure
- Executing Tests
- Suite Test
- Ignore Test
- Group Test
- Exception Test
- Dependency Test
- Parametrized Test
- JUnit Tests
- Test Reports
- Running tests without Eclipse
- Plugin with ANT
Environment
A computer capable of running Java. IntelliJ Community IDE is also required for this course.
Prerequisites
Good knowledge of Java programming language and eclipse is essential.
Audience
Students looking to get started with TestNG
Learning Objectives
This tutorial will get you started with TestNG.
Author: Subject Coach
Added on: 12th Mar 2015
You must be logged in as Student to ask a Question.
None just yet!