Use your business data to your advantage with the help of Syncfusion’s new data science offerings. Discover how a custom big data solution can provide your company with valuable predictions about key market trends.

Want this title & more?

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

Varun Menon

Varun Menon is a QA consultant with several years of experience in developing automation frameworks on various technologies and languages such as Java, JavaScript, Ruby, and Groovy. He has worked on web and mobile applications for some of the leading clients in the field of supply chain management, online photo books, video analytics, and market research.
He blogs at http://blog.varunin.com and is active on Stack Overflow, Selenium, and robotium groups. He is also the author of an upcoming open source android automation tool Bot-bot, which has record and re-play features like Selenium.
He currently holds the position of QA Architect at Pramati Technologies Private Limited, Hyderabad, India.

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.