This sample demonstrates the JUnit support in Citrus. We write some JUnit Citrus test cases that test the REST API of the todo sample application. The JUnit support is
also described in detail in reference guide

Objectives

The todo-list sample application provides a REST API for managing todo entries.
Citrus is able to call the API methods as a client in order to validate the Http response messages.

In test cases we can reference this client component in order to send REST calls to the server. Citrus is able to integrate with JUnit as test execution framework. You can use
the JUnit4CitrusTestRunner implementation as base for your test.

The JUnit4CitrusTestRunner makes sure that Citrus framework is loaded at startup and all configuration is done properly. Also we need to set the annotation @CitrusTest on our test methods in
addition to the normal JUnit @Test annotation. This way we can inject Citrus endpoints such as the todoClient and we can use the runner Java fluent API in Citrus to send and receive messages using that client component.

As an alternative to that you can also use the test designer fluent API. You need to extend from JUnit4CitrusTestDesigner base class then. The other concepts and configuration stays the same.

Last not least we can also use resource injection to the test methods using @CitrusResource method parameter annotations.

We can inject method parameters such as @CitrusResource annotated TestRunner that is our entrance to the Citrus Java fluent API.

We can use the Citrus Java DSL fluent API in the JUnit test in order to exchange messages with the todo application system under test. The test is a normal JUnit test that is executable via Java IDE or command line using Maven or Gradle.

In order to setup Maven for JUnit we need to add the dependency to the project POM file.