Course in JUnit Tests

Course in writing unit tests using Java JUnit

Unit testing is nowadays a pre-requisite to maintain high coding quality. In this course you will learn about the JUnit version 5, AssertJ assertions, how to apply mock objects and much more during this fully loaded course day.

This course appeal to Java developers that are starting as a member of a Java project and need to quickly be productive in writing unit tests using JUnit.

This is what you will learn
  • The principles behind unit testing
  • The principles behind test-driven development (TDD)
  • JUnit version 5
  • Test method annotations
  • Assertions and matchers
  • Usage of AssertJ assertions
  • Repeated tests
  • Parameterized tests
  • Parallell execution of tests
  • Dynamically generated test
  • Conditionally executed tests
  • The principles for mock objects and usage of Mockito
  • JUnit together with build tools as Maven and Gradle
  • Overview of other testing frameworks
Course Contents

Unit Testing and Test-Driven Development

  • Background of JUnit
  • What is a unit test
  • What is an integration test
  • What other form of tests are there
  • What is TDD (Test-Driven Development)
  • Installation of JUnit

Basic JUnit Usage

  • Installation of JUnit
  • Test methods
  • Test method annotations
  • Using test assertions
  • Using display names
  • Running inside IntelliJ (or your favorite IDE)
  • Compiling and running tests from the command-line

Assertions

  • Assertions overview
  • Optional messages
  • Checking for equality of primitive types
  • Checking for equality of objects
  • Checking for equality of iterables
  • Checking for matching lines
  • Checking for thrown exceptions
  • Checking for time-limited execution
  • Grouped assertions
  • Assertion guards
  • Direct failure

Life-Cycle Methods

  • Loading test data files
  • BeforeEach / AfterEach annotations
  • BeforeAll / AfterAll annotations
  • Nested test classes

Conditonal Test Execution

  • Assumptions
  • Enable/disable test based on OS
  • Enable/disable test based on JRE version
  • Enable/disable test based on JVM system property value
  • Enable/disable test based on OS environment varíable value
  • Enable/disable test based on result of JavaScript expression

Build Tool Support

  • Application builds
  • Build tool evolution
  • What is a dependency
  • What is an artefact repository
  • How to find 3rd party libraries
  • What is transitive dependency
  • Source code organization of a project directory
  • What is Maven
  • Sample POM
  • Maven commands
  • Maven build phases
  • How to run tests in Maven
  • Maven test results report
  • What is Gradle
  • Dependencies in Gradle
  • Sample Gradle build file
  • The Gradle wrapper
  • Gradle test support
  • How to run tests in Gradle
  • Gradle test results report

Using Assertion Libraries

  • What is an assertion library
  • What is Hamcrest
  • What is AssertJ
  • Instalaltion of AssertJ
  • Usage of AssertJ

Mock Objects

  • What is a mock object and why you want to use it
  • Overview of some mock-objects libraries
  • Using Mockito
  • Creating mock objects
  • Setting up the expected behaviour of the test's surrounding
  • Verifying the outcome
  • Argument matchers
  • Mock annotation

Test Variants

  • JUnit 5 configuration
  • Parallel test method execution
  • Repeated tests
  • Parameterized tests
  • Parameterized based on simple values
  • Parameterized based on enum values
  • Parameterized based on values factory method
  • Parameterized based on CSV values
  • Dynamically generated tests

Other Testing Frameworks

  • TestNG
  • Spock
Facts
NameJUnit Tests
Duration 1 Days
Level Intermediate
AudienceJava programmers
Prerequisites Practical knowledge in Java programming
Tools
  • Java JDK, version 10+
  • JetBrains IntelliJ IDEA
On-Site Course

If you order an On-Site course, we will come to you and hold the course in your office. The price is determined by our price model and is based on the number of course days, number of participants and any travel and lodging.

Read more about out price modell and term of sales here.

Related Courses
CourseDaysLevel
Java Basics5 BeginnerShow
Java Intermediate3IntermediateShow