training

NL/EN
Deze training is beschikbaar in het Nederlands en Engels. Meer informatie

Unit Testing in Java

Wees productiever door Test-Driven Development (TDD), door advanced tools en frameworks te gebruiken en best practices voor unit testing toe te passen

11 februari 2025
- Veenendaal / Remote
2 dagen
1480 (ex BTW)

Beschrijving

In deze praktische training leren we je alles wat je moet weten om effectieve en onderhoudbare unit tests te schrijven met Java.

Je leert hoe je Test Driven Development (TDD) kunt gebruiken om bugs vroegtijdig te ontdekken, evenals wanneer je black-box versus white-box testing moet gebruiken. We duiken ook in de wereld van mocking met de Mockito mocking library, waarbij je leert waarom en hoe je dit effectief kunt gebruiken. Je leert over metrics zoals code coverage en mutation testing, en we zullen best practices bekijken die je helpen om efficiënte en hoogwaardige tests te schrijven. We sluiten af door implementatie van integratietests met Testcontainers, zodat je er zeker van kunt zijn dat jouw code naadloos samenwerkt met andere onderdelen van je applicatie.

Na het volgen van deze training ben je goed uitgerust om unit tests te schrijven die bugs vroegtijdig opsporen, makkelijker te onderhouden zijn en je een betere Java -ontwikkelaar maken.

Benodigde voorkennis

Java programmeren of zie voorkennis trainingen op deze pagina.

Onderwerpen

  1. About testing
  2. Unit testing basics
  3. Test Driven Development (TDD)
  4. Concept of mocking
  5. Code coverage
  6. Mocking with Mockito
  7. JUnit 5
  8. Best practices
  9. Mutation testing
  10. Integration testing

About testing

In this chapter, you will learn the basics of testing. Why we test and what kind of tests there are.

Goals:

  • Know the difference between linting and testing.
  • Learn how to categorize all the different kinds of tests.
  • Know the testing pyramid and how it can help you to reason about test levels.
  • Learn the common anti-patterns and how to recognize them

Unit testing basics

In this chapter, we'll learn the basics of unit testing using the practical example.

Goals:

  • Learn how to define the 'unit' to test.
  • Learn the difference between white-box and black-box testing.
  • Learn to recognize and use naming strategies for our tests.
  • Know how to determine when you are 'done' with unit testing.
  • Learn basic best practices
  • Lab: implement unit tests for a simple library.

Test Driven Development (TDD)

In this chapter, you will learn what TDD is by example.

Goals:

  • Learn TDD using the red-green-refactor cycle.
  • Lab: Implement a simple library function in a TDD way

Concept of mocking

In this chapter, you will learn what 'mocking' entails and identify where you should use it by identifying your 'system under test' (SUT) and splitting from your 'dependencies'

Goals:

  • Learn to identify the SUT from its dependencies
  • Learn how to write a mock by hand
  • Understand the need for dependency injection when working with mocks.
  • Lab: implement dependency injection and setup mocking using classes.

Code Coverage

In this chapter, we will focus on testing metrics, namely code coverage. Goals:

  • Know what the difference is between code coverage and mutation testing.
  • Know what kinds of coverage metrics there are and how to choose between them.
  • Learn the benefits of a quick feedback cycle with code coverage.
  • Learn how to run code coverage on our code using the command line.
  • Know how to 'break the build' when coverage is too low.
  • Lab: use code coverage to improve our tests.

Mocking with Mockito

In this chapter, you will learn to use a mocking library. We will focus on Mockity, the most popular mocking library.

Goals:

  • Learn how to install Mockito in your project
  • Learn the API; how to create mocks, configure them using when() and verify behavior using verify()
  • Know to use argument matchers.
  • Lab: Implement your tests using Mockito

JUnit 5

In this chapter, we look closely at JUnit, Java's most popular testing framework.

Goals:

  • Know the different parts that make up the JUnit platform
  • Learn to work with the assertions API.
  • Learn how 'assumptions' can help in advanced scenarios.
  • Learn the test lifecycle and how to use it to improve our tests.
  • Lab: Improve our test maintainability using features of JUnit

Best practices

In this chapter, we will look at some best practices we can use to improve the maintainability of our tests further.

Goals:

  • Know how to identify tests that are too DRY (Don't Repeat Yourself) or too WET (We Like Typing).
  • Learn to prefer DAMP tests (Descriptive and Meaningful Phrases).
  • Know when to use a builder pattern
  • Know where to find more best practices
  • Lab: Implement DAMP tests using the builder pattern.

Mutation testing

In this chapter, we will focus on testing metrics, namely mutation testing.

Goals:

  • Know what the difference is between code coverage and mutation testing
  • Understand how mutation testing works conceptually.
  • Learn what the "mutation score" metric is
  • Learn how to use Pitest to run mutation testing on Java code.
  • Know how to read a mutation testing report.
  • Know how to 'break the build' when the mutation score is too low.
  • Lab: Improve the effectiveness of your tests using Pitest.

Integration testing

In this chapter, we'll be 'scaling up the pyramid': Welcome to integration testing.

Goals:

  • Be able to identify where an integration test is needed.
  • Learn to identify 'shared state' in dependencies.
  • Learn how to use Testcontainers to create dependencies on the fly.
  • Know what the benefits are of using Testcontainers
  • Learn to organize integration tests inside your project structure.
  • Lab: Implement integration tests for a database using Testcontainers

Planning

StartdatumDuurLocatie
11 februari 202512 februari 2025
2 dagen
Veenendaal / Remote
Dit is een hybride training die remote gevolgd kan worden. Meer informatie
Veenendaal / Remote
Dit is een hybride training die remote gevolgd kan worden. Meer informatie
Inschrijven
2 april 20253 april 2025
2 dagen
Utrecht / Remote
Dit is een hybride training die remote gevolgd kan worden. Meer informatie
Utrecht / Remote
Dit is een hybride training die remote gevolgd kan worden. Meer informatie
Inschrijven
Houd me op de hoogte van nieuwe data

Incompany of persoonlijk advies nodig?

Onze opleidingsadviseurs denken graag met je mee om een persoonlijk advies te geven of een incompany training binnen jouw organisatie te vinden.

Trainers

Voorkennis trainingen

"Ontzettend goede leraar."
Sander
  • icon

    Hoge waardering

  • icon

    Praktijkgerichte trainingen

  • icon

    Gecertificeerde trainers

  • icon

    Eigen docenten