You are previewing TestNg Beginner's Guide.
O'Reilly logo
TestNg Beginner's Guide

Book Description

Write robust unit and functional tests with the power of TestNG

  • Step-by-step guide to learn and practise any given feature

  • Detailed understanding of the features and core concepts

  • Learn about writing custom reporting

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.

Table of Contents

  1. TestNg Beginner's Guide
    1. Table of Contents
    2. TestNg Beginner's Guide
    3. Credits
    4. About the Author
    5. Acknowledgement
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    8. Preface
      1. Introduction
      2. What this book covers
      3. What you need for this book
      4. Who this book is for
      5. Conventions
      6. Time for action – heading
        1. What just happened?
        2. Pop quiz – heading
        3. Have a go hero
      7. Reader feedback
    9. 1. Getting Started
      1. Testing and test automation
      2. TestNG
      3. Features of TestNG
      4. Downloading TestNG
        1. Prerequisites
      5. Installing TestNG onto Eclipse
      6. Time for action – installing TestNG onto Eclipse
        1. What just happened?
      7. Writing your first TestNG test
        1. The Java project
      8. Time for action – creating a Java project
        1. What just happened?
      9. Time for action – creating your first TestNG class
        1. What just happened?
      10. Running your first test program
      11. Time for action – running tests through Eclipse
        1. Have a go hero
        2. Pop quiz – about TestNG
      12. Summary
    10. 2. Understanding testng.xml
      1. About testng.xml
      2. Creating a test suite
      3. Time for action – creating a test suite
      4. Running testng.xml
        1. Using command prompt
      5. Time for action – running testng.xml through the command prompt
        1. What just happened?
        2. Using Eclipse
      6. Time for action – executing testng.xml using Eclipse
      7. Time for action – configuring Eclipse to run a particular TestNG XML file
        1. What just happened?
      8. Creating multiple tests
      9. Time for action – testng XML with multiple tests
        1. What just happened?
      10. Adding classes, packages, and methods to test
        1. Sample project
        2. Creating a test with classes
      11. Time for action – creating a test with classes
        1. What just happened?
        2. Creating a test using packages
      12. Time for action – creating a test with packages
        1. What just happened?
        2. Creating a test with methods
      13. Time for action – creating a test with methods
        1. What just happened?
        2. Creating a test with packages, classes, and methods
      14. Time for action – creating a test suite with package, class, and test method
        1. What just happened?
      15. Including and excluding
        1. Include/exclude packages
      16. Time for action – test suite to include a particular package
      17. Time for action – test suite to exclude a particular package
        1. What just happened?
        2. Include/exclude methods
      18. Time for action – test suite to exclude a particular method
        1. Using regular expressions to include/exclude
          1. Prerequisite – creating a sample project
      19. Time for action – using regular expressions for test
        1. What just happened?
        2. Have a go hero
        3. Pop quiz – TestNG XML
      20. Summary
    11. 3. Annotations
      1. Annotations in TestNG
      2. Before and After annotations
      3. Time for action – running the Before and After annotations
        1. What just happened?
      4. Time for action – Before and After annotation when extended
        1. What just happened?
      5. Test annotation
      6. Time for action – using test annotation on class
        1. What just happened?
      7. Disabling a test
      8. Time for action – disabling a test method
        1. What just happened?
      9. Exception test
      10. Time for action – writing an exception test
        1. What just happened?
      11. Time for action – writing a exception test verifying message
        1. What just happened?
      12. Time test
      13. Time for action – time test at suite level
        1. What just happened?
      14. Time for action – time test at test method level
        1. What just happened?
      15. Parameterization of test
        1. Parameterization through testng.xml
      16. Time for action – parameterization through testng.xml
        1. What just happened?
      17. Time for action – providing optional values
        1. What just happened?
      18. DataProvider
      19. Time for action – using Test annotation on Class
        1. What just happened?
      20. Time for action – DataProvider in different class
        1. What just happened?
        2. Have a go hero
        3. Pop quiz – annotations
      21. Summary
    12. 4. Groups
      1. Grouping tests
      2. Time for action – creating test that belong to a group
        1. What just happened?
      3. Running a TestNG group
        1. Using Eclipse
      4. Time for action – running a TestNG group through Eclipse
        1. What just happened?
        2. Using the testng XML
      5. Time for action – running a TestNG group using the testng XML
        1. What just happened?
      6. Test that belong to multiple groups
      7. Time for action – creating a test having multiple groups
        1. What just happened?
      8. Including and excluding groups
      9. Time for action – including/excluding groups using the testng XML
        1. What just happened?
      10. Using regular expressions
      11. Time for action – using regular expressions in the testng XML
        1. What just happened?
      12. Default group
      13. Time for action – assigning a default group to a set of tests
        1. What just happened?
      14. Group of groups
      15. Time for action – running a TestNG group using the testng XML
        1. What just happened?
        2. Have a go hero
        3. Pop quiz – groups
      16. Summary
    13. 5. Dependencies
      1. Dependency test
        1. Test with single test method dependency
      2. Time for action – creating a test that depends on another test
        1. What just happened?
        2. Test that depends on multiple tests
      3. Time for action – creating a test that depends on multiple tests
        1. What just happened?
        2. Inherited dependency test
      4. Time for action – creating a test that depends on inherited tests
        1. What just happened?
        2. Have a go hero
      5. Dependent groups
      6. Time for action – creating a test that depends on a group
        1. What just happened?
        2. Depending on methods from different classes
      7. Time for action – depending on a method from a different class
        1. What just happened?
      8. Using regular expressions
      9. Time for action – using regular expressions
        1. What just happened?
        2. Have a go hero
      10. XML-based dependency configuration
        1. Simple group dependency
      11. Time for action – using simple dependency in XML
        1. What just happened?
        2. Multigroup dependency
      12. Time for action – defining multigroup dependency in XML
        1. What just happened?
        2. Using regular expressions for defining dependency
      13. Time for action – using regular expressions for dependency
        1. What just happened?
        2. Pop quiz – dependencies
      14. Summary
    14. 6. The Factory Annotation
      1. What is factory?
        1. First factory program
      2. Time for action – first factory test
        1. What just happened?
      3. Passing parameters to test classes
      4. Time for action – passing parameters to test classes
        1. What just happened?
      5. Using DataProvider along with the @Factory annotation
      6. Time for action – using DataProvider with Factory
        1. What just happened?
      7. DataProvider or Factory
      8. Time for action – the DataProvider test
        1. What just happened?
      9. Time for action – the Factory test
        1. What just happened?
      10. Dependency with the @Factory annotation
      11. Time for action – dependency with the @Factory annotation
        1. What just happened?
      12. Time for action – running a dependency test sequentially
        1. What just happened?
        2. Have a go hero
        3. Pop quiz – the Factory annotation
      13. Summary
    15. 7. Parallelism
      1. Parallelism
        1. A simple multithreaded test
      2. Time for action – writing first parallel test
        1. What just happened?
      3. Running test methods in parallel
      4. Time for action – running test methods in parallel
        1. What just happened?
      5. Running test classes in parallel
      6. Time for action – running test classes in parallel
        1. What just happened?
      7. Running tests inside a suite in parallel
      8. Time for action – running tests inside a suite in parallel
        1. What just happened?
      9. Configuring an independent test method to run in multiple threads
      10. Time for action – running independent test in threads
        1. What just happened?
        2. Have a go hero
      11. Advantages and uses
        1. Pop quiz – parallelism
      12. Summary
    16. 8. Using Build Tools
      1. Build automation
        1. Advantages of build automation
      2. Different build tools available
        1. Ant
          1. Installing Ant
          2. Using Ant
      3. Time for action – using Ant to run TestNG tests
        1. What just happened?
          1. Different configurations to be used with TestNG task
        2. Have a go hero
        3. Maven
          1. Installing Maven
          2. Using Maven
      4. Time for action – using Maven to run TestNG tests
        1. What just happened?
          1. Different configurations to be used with Maven
        2. Have a go hero
        3. Pop quiz – build tools
      5. Summary
    17. 9. Logging and Reports
      1. Logging and reporting
      2. Writing your own logger
      3. Time for action – writing a custom logger
        1. What just happened?
      4. Writing your own reporter
      5. Time for action – writing a custom reporter
        1. What just happened?
      6. TestNG HTML and XML report
      7. Time for action – generating TestNG HTML and XML reports
        1. What just happened?
      8. Generating a JUnit HTML report
      9. Time for action – generating a JUnit report
        1. What just happened?
      10. Generating a ReportNG report
      11. Time for action – generating a ReportNG report
        1. What just happened?
        2. ReportNG configuration options
        3. Have a go hero
      12. Generating a Reporty-ng (former TestNG-xslt) report
      13. Time for action – generating a Reporty-ng report
        1. What just happened?
        2. Configuration options for Reporty-ng report
        3. Have a go hero
        4. Pop quiz – logging and reports
      14. Summary
    18. 10. Creating a Test Suite through Code
      1. Running TestNG programmatically
      2. Time for action – running TestNG programmatically
        1. What just happened?
        2. Have a go hero
      3. Parameterization of tests
      4. Time for action – passing parameter values
        1. What just happened?
      5. Include and exclude
        1. Include/exclude methods
      6. Time for action – including test methods
        1. What just happened?
        2. Have a go hero
        3. Include/exclude groups
      7. Time for action – including/excluding groups
        1. What just happened?
        2. Have a go hero
      8. Dependency test
      9. Time for action – configuring a dependency test
        1. What just happened?
        2. Pop quiz – creating a test suite through code
      10. Summary
    19. 11. Migrating from JUnit
      1. Running your JUnit tests through TestNG
      2. Time for action – writing a JUnit test
        1. What just happened?
        2. Running your JUnit Tests through TestNG using the testng XML
      3. Time for action – running JUnit tests through TestNG
        1. What just happened
        2. Running JUnit and TestNG tests together with TestNG XML
      4. Time for action – running JUnit and TestNG tests together
        1. What just happened?
        2. Have a go hero
      5. Running JUnit tests along with TestNG through Ant
      6. Time for action – running JUnit and TestNG tests through Ant
        1. What just happened?
      7. Migrating from JUnit to TestNG
      8. Time for action – converting a JUnit test to a TestNG test
        1. What just happened?
        2. Pop quiz – migrating from JUnit
      9. Summary
    20. 12. Unit and Functional Testing
      1. Unit testing with TestNG
      2. Time for action – unit testing with TestNG
        1. What just happened?
        2. Have a go hero
      3. Assertion with TestNG
      4. Mocking
        1. Different mocking strategies
      5. Mocking with TestNG
        1. Jmock
      6. Time for action – using JMock with TestNG
        1. What just happened?
        2. Have a go hero
        3. Mockito
      7. Time for action – using Mockito
        1. What just happened?
      8. Functional testing
      9. TestNG with Selenium
      10. Time for action – using Selenium with TestNG
        1. What just happened?
        2. Pop quiz – unit and functional testing
      11. Summary
    21. A. Pop Quiz Answers
      1. Chapter 1, Getting Started
        1. Pop quiz – about TestNG
      2. Chapter 2, Understanding testng.xml
        1. Pop quiz – TestNG XML
      3. Chapter 3, Annotations
        1. Pop quiz – annotations
      4. Chapter 4, Groups
        1. Pop quiz – groups
      5. Chapter 5, Dependencies
        1. Pop quiz – dependencies
      6. Chapter 6, The Factory Annotation
        1. Pop quiz – the Factory annotation
      7. Chapter 7, Parallelism
        1. Pop quiz – parallelism
      8. Chapter 8, Using Build Tools
        1. Pop quiz – build tools
      9. Chapter 9, Logging and Reports
        1. Pop quiz – logging and reports
      10. Chapter 10, Creating a Test Suite through Code
        1. Pop quiz – creating a test suite through code
      11. Chapter 11, Migrating from JUnit
        1. Pop quiz – migrating from JUnit
      12. Chapter 12, Unit and Functional Testing
        1. Pop quiz – unit and functional testing
    22. Index