Working with TestNG - Starters Guide
Chapters
Working with JUnit tests in TestNG
TestNG provides an option to shift to JUnit test, TestNG can automatically identify and execute Junit tests. User can execute already created JUnit test cases using TestNG.
Let's check this example to understand it better
Create JUnit Test Case Class:
package jUnit; import org.junit.Test; public class JunitDemo1 { @Test public void method1() { System.out.println("Welcome to JUnit"); } }
Create testing.xml file as shown below.
Note: Here we need define the property junit="true" in testing.xml file to execute the JUnit test cases as shown below.
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite for conversion"> <test name="JUnit test case" junit="true"> <classes> <class name="jUnit.JunitDemo1"/> </classes> </test> </suite>
Run the testing.xml file by click on run button in eclipse.
The Output is:
So you can see that its as simple as setting an additonal attribute junit="true"
in test
case element under testing.xml
, which allows to testNG to make a switch over to JUnit automatically.
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!