PacktLib: TestNG Beginner's Guide

TestNg Beginner's Guide

Credits

About the Author

Acknowledgement

About the Reviewers

www.PacktPub.com

Preface

Getting Started

Testing and test automation

TestNG

Features of TestNG

Downloading TestNG

Installing TestNG onto Eclipse

Time for action – installing TestNG onto Eclipse

Writing your first TestNG test

Time for action – creating a Java project

Time for action – creating your first TestNG class

Running your first test program

Time for action – running tests through Eclipse

Summary

Understanding testng.xml

About testng.xml

Creating a test suite

Time for action – creating a test suite

Running testng.xml

Time for action – running testng.xml through the command prompt

Time for action – executing testng.xml using Eclipse

Time for action – configuring Eclipse to run a particular TestNG XML file

Creating multiple tests

Time for action – testng XML with multiple tests

Adding classes, packages, and methods to test

Time for action – creating a test with classes

Time for action – creating a test with packages

Time for action – creating a test with methods

Time for action – creating a test suite with package, class, and test method

Including and excluding

Time for action – test suite to include a particular package

Time for action – test suite to exclude a particular package

Time for action – test suite to exclude a particular method

Time for action – using regular expressions for test

Summary

Annotations

Annotations in TestNG

Before and After annotations

Time for action – running the Before and After annotations

Time for action – Before and After annotation when extended

Test annotation

Time for action – using test annotation on class

Disabling a test

Time for action – disabling a test method

Exception test

Time for action – writing an exception test

Time for action – writing a exception test verifying message

Time test

Time for action – time test at suite level

Time for action – time test at test method level

Parameterization of test

Time for action – parameterization through testng.xml

Time for action – providing optional values

DataProvider

Time for action – using Test annotation on Class

Time for action – DataProvider in different class

Summary

Groups

Grouping tests

Time for action – creating test that belong to a group

Running a TestNG group

Time for action – running a TestNG group through Eclipse

Time for action – running a TestNG group using the testng XML

Test that belong to multiple groups

Time for action – creating a test having multiple groups

Including and excluding groups

Time for action – including/excluding groups using the testng XML

Using regular expressions

Time for action – using regular expressions in the testng XML

Default group

Time for action – assigning a default group to a set of tests

Group of groups

Time for action – running a TestNG group using the testng XML

Summary

Dependencies

Dependency test

Time for action – creating a test that depends on another test

Time for action – creating a test that depends on multiple tests

Time for action – creating a test that depends on inherited tests

Dependent groups

Time for action – creating a test that depends on a group

Time for action – depending on a method from a different class

Using regular expressions

Time for action – using regular expressions

XML-based dependency configuration

Time for action – using simple dependency in XML

Time for action – defining multigroup dependency in XML

Time for action – using regular expressions for dependency

Summary

The Factory Annotation

What is factory?

Time for action – first factory test

Passing parameters to test classes

Time for action – passing parameters to test classes

Using DataProvider along with the @Factory annotation

Time for action – using DataProvider with Factory

DataProvider or Factory

Time for action – the DataProvider test

Time for action – the Factory test

Dependency with the @Factory annotation

Time for action – dependency with the @Factory annotation

Time for action – running a dependency test sequentially

Summary

Parallelism

Parallelism

Time for action – writing first parallel test

Running test methods in parallel

Time for action – running test methods in parallel

Running test classes in parallel

Time for action – running test classes in parallel

Running tests inside a suite in parallel

Time for action – running tests inside a suite in parallel

Configuring an independent test method to run in multiple threads

Time for action – running independent test in threads

Advantages and uses

Summary

Using Build Tools

Build automation

Different build tools available

Time for action – using Ant to run TestNG tests

Time for action – using Maven to run TestNG tests

Summary

Logging and Reports

Logging and reporting

Writing your own logger

Time for action – writing a custom logger

Writing your own reporter

Time for action – writing a custom reporter

TestNG HTML and XML report

Time for action – generating TestNG HTML and XML reports

Generating a JUnit HTML report

Time for action – generating a JUnit report

Generating a ReportNG report

Time for action – generating a ReportNG report

Generating a Reporty-ng (former TestNG-xslt) report

Time for action – generating a Reporty-ng report

Summary

Creating a Test Suite through Code

Running TestNG programmatically

Time for action – running TestNG programmatically

Parameterization of tests

Time for action – passing parameter values

Include and exclude

Time for action – including test methods

Time for action – including/excluding groups

Dependency test

Time for action – configuring a dependency test

Summary

Migrating from JUnit

Running your JUnit tests through TestNG

Time for action – writing a JUnit test

Time for action – running JUnit tests through TestNG

Time for action – running JUnit and TestNG tests together

Running JUnit tests along with TestNG through Ant

Time for action – running JUnit and TestNG tests through Ant

Migrating from JUnit to TestNG

Time for action – converting a JUnit test to a TestNG test

Summary

Unit and Functional Testing

Unit testing with TestNG

Time for action – unit testing with TestNG

Assertion with TestNG

Mocking

Mocking with TestNG

Time for action – using JMock with TestNG

Time for action – using Mockito

Functional testing

TestNG with Selenium

Time for action – using Selenium with TestNG

Summary

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Pop Quiz Answers

Index