Assumptions

Learn about Assumptions in JUnit 5.

We'll cover the following

At times, we have to make sure a set of preconditions are fulfilled before executing the test.

These preconditions may be necessary due to a number of external factors—such as environment configuration, or if we want to run the test only on the continuous integration (CI) environment and not on the local developer machine.

We can achieve this conditional test execution using the assumption methods. These methods are part of the org.junit.jupiter.api.Assumptions class.

The following are some cases where assumptions are useful:

  • To run tests only in CI environments and exclude developer machines.
  • To run tests based on some external environment configuration.
  • To run tests only on a specific operating system (OS).

Assumptions

The following are some methods that are part of the org.junit.jupiter.api.Assumptions class.

Get hands-on with 1200+ tech skills courses.