Instructional strategies for Testing
Microservices with Arquillian
Objectives
•
Implement a microservice test case using Arquillian.
18
JB283-RHOAR1.0-en-1-20180517

Presentation Notes
Presentation Notes
Introduction
This section introduces Arquillian, a testing framework that starts up WildFly Swarm to enable all
the facilities from MicroProfile specification, such as the context and dependency injection (CDI)
container and the RESTEasy runtime environment. Arquillian is a wide subject and we will keep
the presentation short to avoid going into the details.
Lecture
For audiences with some Arquillian knowledge, you must just stress the
@CreateSwarm
annotation. It configures the variables needed by WildFly Swarm to start, such as port numbers
and logging facilities. It is important to mention the
@Deployment
class-level annotation
however it is also important to enforce that for this course this annotation would not work
because the classes from a single microservice are not stored in a segregated package.
For audiences without Arquillian knowledge, mention that Arquillian triggers not only the WildFly
Swarm infrastructure, but it may be used for other containers as well, such as EAP, WebSphere,
WebLogic, among other options. Walk through the source code in the demo to make sure they
understand how WildFly Swarm is started and how the tests are emulating an external call.
Demonstration
The idea in the demonstration is to use Arquillian's extension to package the resulting file to
deploy it on WildFly Swarm. Initially, you need to create a WebArchive object that contains
all the dependencies, classes, and configuration files used by WildFly Swarm to start up the
infrastructure. Later you will discuss the test, using some test extensions to simplify the REST
endpoint invocations.
Guided Exercise
Tell your students to turn to the guided exercise in their books. When the students have
completed the exercise, discuss the activity and solution. The tests take some time to start and
run, so please be patient with the them.
Summary
Microservices testing with MicroProfile implementation requires the startup of the whole
microservice to test it properly. Use Arquillian to simplify this task.
Instructional strategies for Testing
Microservices with Mock Frameworks
Objectives
•
Implement a microservice test using mock frameworks.
JB283-RHOAR1.0-en-1-20180517
19

Chapter4.Testing Microservices
Presentation Notes
Introduction
Testing REST endpoints that are connected with other microservices mandates you to create
a clean and readable test. Unfortunately, invoking the REST endpoints may become a mess
due to the REST client API calls. To minimize the confusion, use REST Assured, which uses an
elegant but readable fluent interface. Also, for microservice endpoints that depends on external
microservices, use WireMock. It starts a web server that responds to the requests made to a
REST endpoint. Finally, to test source code implementation on an integration test, you may use
Mockito, that emulates responses from an API.
