5 Testing Quarkus applications

 

This chapter covers

  • Discovering how Quarkus testing integrates with JUnit
  • Developing tests that can execute with a traditional JVM as well as a native binary
  • Using testing profiles to run tests with different configurations
  • Creating testing mocks of remote services

In chapter 3, we already discussed some aspects of Quarkus application testing, namely the ability to test them continuously using the Dev mode. We also experimented with the Dev Services, which is the ability to automatically run instances of services needed for testing, such as databases or message brokers.

In this chapter, we dive a bit deeper into the capabilities that Quarkus provides for the testing of your applications. We explain the integration of Quarkus with JUnit 5, learn how to execute tests in native mode easily, and how to use testing profiles to execute tests with different configurations in one go. We also look at the facilities for creating mocks of CDI beans that are not suitable to be used directly during test execution. All these features are neatly integrated into Quarkus. We’re sure you’ll get accustomed to them quickly, saving a lot of time, effort, and nerves compared to traditional testing approaches with different platforms.

5.1 Writing tests

5.1.1 Writing a simple test for the Reservation repository

5.2 Native testing

5.2.1 Writing a test for the Reservation resource

5.3 Mocking

5.3.1 Mocking by replacing implementations

5.3.2 Mocking with Mockito

5.4 Testing profiles

5.5 Next steps

Summary