Free Sample
+ Collection

TestNG Beginner's Guide

Beginner's Guide
Varun Menon

Write robust unit and functional tests with the power of TestNG
$26.99
$44.99
RRP $26.99
RRP $44.99
eBook
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781782166009
Paperback276 pages

About This Book

  • Step-by-step guide to learn and practise any given feature
  • Detailed understanding of the features and core concepts
  • Learn about writing custom reporting

Who This Book Is For

This book is great for developers and testers who are new to TestNg and want to learn how to use TestNG for writing their application as well as functional tests. This book assumes that you have experience in Java and OOPs concepts and have worked with certain IDE.

Table of Contents

Chapter 1: 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
Chapter 2: 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
Chapter 3: 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
Chapter 4: 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
Chapter 5: 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
Chapter 6: 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
Chapter 7: 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
Chapter 8: 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
Chapter 9: 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
Chapter 10: 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
Chapter 11: 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
Chapter 12: 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

What You Will Learn

  • Learn about TestNG and its advantages over other frameworks
  • Configure/write test-suites in TestNG
  • Learn about different Before/After annotations and how to use each one of them
  • Pass values to your tests at runtime and make Data-driven tests
  • Run tests in parallel
  • Define and configure test-suites at runtime
  • Extend TestNG to handle test-execution and generate custom reports.
  • Include and exclude tests based on the search criteria to your test-suite

In Detail

Unit/Functional testing has now become part of every development life cycle. Junit was once the main framework that was used by developers for the purpose of Unit testing when it came to Java. But Junit had certain limitations in terms of execution and features. This book explains about the features and usage of TestNg, a new framework that overcomes Junit’s limitations and provides a lot of extra features.

TestNg Beginner’s Guide is a practical, hands-on guide that aims to increase your knowledge of TestNg. This step-by-step guide will help you to learn and understand the different TestNg features, and you will learn about the advantages and how to use and configure each feature according to your needs.

This book explains the various features of the TestNG testing framework. It provides a step-by-step guide that explains the different features with practical examples and sample programs.You will also learn about how to use and configure each feature based on different test scenarios. We will also take a look at extending TestNG to add custom logging and test-reports. If you are a beginner in TestNG or test frameworks, then this book will help you in learning, practising, and getting started with TestNg.

Authors

Read More

Recommended for You

Advanced Penetration Testing for Highly-Secured Environments [Video]
$ 25.50
Instant Penetration Testing: Setting Up a Test Lab How-to
$ 14.99
Advanced Penetration Testing for Highly-Secured Environments: The Ultimate Security Guide
$ 35.99
Building Virtual Pentesting Labs for Advanced Penetration Testing
$ 35.99