TestNG Executing Tests - TestNG

How the Test cases are executed using TestNG?

TestNG class us used to execute the test cases. In TestNG framework, the main point for running the tests is TestNG class. The TestNG objects can be created by the user and the objects can be invoked in different ways like:

  • On an existing testng.xml.
  • On a synthetic testng.xml, created entirely from Java.
  • By directly setting the test classes.

The groups that are to be included or excluded can be defined by the user, and also the parameters can be assigned. The command line parameters include:

  • -d outputdir: specify the output directory.
  • -testclass class_name: specifies one or several class names.
  • -testjar jar_name: specifies the jar containing the tests.
  • -sourcedir src1;src2: ; separated list of source directories (used only when javadoc annotations are used).
  • -target
  • -groups
  • -testrunfactory
  • -listener

The TestNG object is created, an already existing testing.xml in the example.

Create a Class

  • The java class that is to be tested is created, MessageUtil.java in C:\>TestNG_WORKSPACE.

Create Test Case Class

  • A java test class SampleTest.java is created.
  • The test method testPrintMessage() is added to the test class.
  • An annotation @Test is added to the testPrintMessage() method.
  • The test condition is implemented and the condition is checked using the assertEquals API of TestNG.

A java class file SampleTest.java is created in C:\>TestNG_WORKSPACE.

Create testng.xml

The test cases are executed by creating testng.xml file in C:\>TestNG_WORKSPACE. The complete XML testing is captured in the file. All the test suites and the parameters are described easily by this file enabling to check in the code repository or e-mail to the co-workers. The subsets of the tests are easily extracted and many runtime configurations are extracted.

Javac is used to compile the test case.

The testng.xml is run, which enables the <test> tag test case to run.

The output is verified.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

TestNG Topics