Mastering Software Testing with JUnit 5

Book description

A comprehensive, hands-on guide on unit testing framework for Java programming language

About This Book

  • In-depth coverage of Jupiter, the new programming and extension model provided by JUnit 5
  • Integration of JUnit 5 with other frameworks such as Mockito, Spring, Selenium, Cucumber, and Docker
  • Best practices for writing meaningful Jupiter test cases

Who This Book Is For

This book is for Java software engineers and testers. If you are a Java developer who is keen on improving the quality of your code and building world class applications then this book is for you. Prior experience of the concepts of automated testing will be helpful.

What You Will Learn

  • The importance of software testing and its impact on software quality
  • The options available for testing Java applications
  • The architecture, features and extension model of JUnit 5
  • Writing test cases using the Jupiter programming model
  • How to use the latest and advanced features of JUnit 5
  • Integrating JUnit 5 with existing third-party frameworks
  • Best practices for writing meaningful JUnit 5 test cases
  • Managing software testing activities in a living software project

In Detail

When building an application it is of utmost importance to have clean code, a productive environment and efficient systems in place. Having automated unit testing in place helps developers to achieve these goals. The JUnit testing framework is a popular choice among Java developers and has recently released a major version update with JUnit 5.

This book shows you how to make use of the power of JUnit 5 to write better software.

The book begins with an introduction to software quality and software testing. After that, you will see an in-depth analysis of all the features of Jupiter, the new programming and extension model provided by JUnit 5. You will learn how to integrate JUnit 5 with other frameworks such as Mockito, Spring, Selenium, Cucumber, and Docker.

After the technical features of JUnit 5, the final part of this book will train you for the daily work of a software tester. You will learn best practices for writing meaningful tests. Finally, you will learn how software testing fits into the overall software development process, and sits alongside continuous integration, defect tracking, and test reporting.

Style and approach

The book offers definitive and comprehensive coverage of all the Unit testing concepts with JUnit and its features using several real world examples so that readers can put their learning to practice almost immediately. This book is structured in three parts:

  1. Software testing foundations (software quality and Java testing)
  2. JUnit 5 in depth (programming and extension model of JUnit 5)
  3. Software testing in practice (how to write and manage JUnit 5 tests)

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Retrospective On Software Quality And Java Testing
    1. Software quality
      1. Quality engineering
        1. Requirements and specification
        2. Quality Assurance
          1. ISO/IEC-25000
      2. Verification and Validation
        1. Software defects
        2. Static analysis
    2. Software testing
      1. Testing levels
        1. Unit testing
        2. Integration testing
        3. System testing
      2. Testing methods
        1. Black-box testing
        2. White-box testing
        3. Non-functional testing
      3. Testing types
      4. Other testing approaches
    3. Testing frameworks for the JVM
      1. JUnit 3
        1. Standard tests in JUnit 3
        2. Test execution in JUnit 3
      2. JUnit 4
        1. Standard tests in JUnit 4
        2. Test execution in JUnit 4
        3. Advanced features of JUnit 4
      3. JUnit ecosystem
    4. Summary
  3. What’s New In JUnit 5
    1. Road to JUnit 5
      1. JUnit 5 motivation
        1. Modularity
        2. JUnit 4 runners
        3. JUnit 4 rules
      2. JUnit 5 inception
      3. JUnit 5 community
    2. JUnit 5 architecture
      1. Test Engine SPI
      2. Test Launcher API
    3. Running tests in JUnit 5
      1. Jupiter tests with Maven
      2. Jupiter tests with Gradle
      3. Legacy tests with Maven
      4. Legacy tests wih Gradle
      5. The ConsoleLauncher
      6. Jupiter tests in JUnit 4
        1. IntelliJ
        2. Eclipse
    4. The extension model of JUnit 5
      1. Test lifecycle
      2. Conditional extension points
      3. Dependency injection
      4. Third-party extensions
    5. Summary
  4. JUnit 5 Standard Tests
    1. Test lifecycle
      1. Test instance lifecycle
      2. Skipping tests
      3. Display names
    2. Assertions
      1. Jupiter assertions
        1. Group of assertions
        2. Asserting exceptions
        3. Asserting timeouts
      2. Third-party assertion libraries
    3. Tagging and filtering tests
      1. Filtering tests with Maven
        1. Maven regular support
      2. Filtering tests with Gradle
      3. Meta-annotations
    4. Conditional test execution
      1. Assumptions
    5. Nested tests
    6. Repeated tests
    7. Migration from JUnit 4 to JUnit 5
      1. Rule support in Jupiter
    8. Summary
  5. Simplifying Testing With Advanced JUnit Features
    1. Dependency injection
      1. TestInfoParameterResolver
      2. RepetitionInfoParameterResolver
      3. TestReporterParameterResolver
    2. Dynamic tests
    3. Test interfaces
    4. Test templates
    5. Parameterized tests
      1. @ValueSource
      2. @EnumSource
      3. @MethodSource
      4. @CsvSource and @CsvFileSource
      5. @ArgumentsSource
      6. Argument conversion
        1. Implicit conversion
        2. Explicit conversion
      7. Custom names
    6. Java 9
      1. JUnit 5 and Java 9 compatibility
    7. Beyond JUnit 5.0
    8. Summary
  6. Integration Of JUnit 5 With External Frameworks
    1. Mockito
      1. Mockito in a nutshell
      2. JUnit 5 extension for Mockito
    2. Spring
      1. Spring in a nutshell
        1. Spring modules
        2. Introduction to Spring Test
        3. Testing Spring Boot applications
      2. JUnit 5 extension for Spring
    3. Selenium
      1. Selenium in a nutshell
      2. JUnit 5 extension for Selenium
    4. Cucumber
      1. Cucumber in a nutshell
      2. JUnit 5 extension for Cucumber
    5. Docker
      1. Docker in a nutshell
      2. JUnit 5 extension for Docker
    6. Android
      1. Android in a nutshell
      2. Gradle plugin for JUnit 5 in Android projects
    7. REST
      1. REST in a nutshell
      2. Using REST test libraries with Jupiter
    8. Summary
  7. From Requirements To Test Cases
    1. The importance of requirements
    2. Test planning
    3. Test design
      1. Equivalence partitioning
      2. Boundary analysis
      3. Test coverage
    4. Software testing principles
      1. The psychology of testing
    5. Test anti-patterns
      1. Code smells
    6. Summary
  8. Testing Management
    1. Software development processes
    2. Continuous Integration
      1. Jenkins
      2. Travis CI
    3. Test reporting
      1. Maven Surefire Report
      2. Allure
    4. Defect-tracking systems
    5. Static analysis
    6. Putting all pieces together
      1. Features and requirements
      2. Design
      3. Tests
    7. Summary

Product information

  • Title: Mastering Software Testing with JUnit 5
  • Author(s): Boni García
  • Release date: October 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787285736