Skip to content

Write and execute a JUnit test for a Java microservice based on MircoProfile and run both in the OpenLiberty development mode

License

Notifications You must be signed in to change notification settings

thomassuedbroecker/local-dev-junit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Write and execute a JUnit test for a Java microservice based on MircoProfile and the OpenLiberty development mode

That blog post contains the technical basics: how to develop a JUnit test for the Authors microservice from the Cloud Native Starter example and run both the Authors microservice and JUnit test on OpenLiberty in the development mode.

That blog post isn't intended to be a blueprint, or a how to guide for writing JUnit tests or how to definition test organization, test strategy and so on. The objective is to get technically started along the concrete microservice example from the Cloud Native Starter project.

You can also visit the OpenLiberty tutorial "MicroProfile or Jakarta EE application" to start with.

The Authors microservice has one RESTful api endpoint called getAuthor. The endpoint provides one parameter for the Author name. The endpoint returns Author data in a JSON format.

You can also visit the OpenLiberty tutorial "MicroProfile or Jakarta EE application" to start with.

The Authors microservice has one RESTful api endpoint called getAuthor. The endpoint provides one parameter for the Author name. The endpoint returns Author data in a JSON format.

What do we need and how do we implement it?

We need to  

  • .. invoke the REST endpoint of the Authors
  • .. microservice with a REST Client.
  • .. transform the JSON response of the REST endpoint to an Author data class
  • .. handle different values to invoke the REST Endpoint parameter for the Author name to run tests with a variations of name.
  • .. compare the actual response value with an expected value and document the result.

The gif shows a sample JUnit test execution in Visual Studio Code of my OpenLiberty project:

junit-on-openliberty-run-test

Questions are how to  

  1. .. setup a JUnit test for the development mode of the OpenLiberty  server
  2. .. convert JSON Data from a String to an Author Java instance with JSON-B
  3. .. define a REST Client?
  4. .. configure parameterized a JUnit test?
  5. .. write the concrete parameterized JUnit test?
  6. .. execute the JUnit test find results test results?

What are the tools and frameworks?

That are the Tools and frameworks I use in my example project:


Additional resources blog posts, videos or manuals

MicroProfile RestClient

JUnit

Jsonb

About

Write and execute a JUnit test for a Java microservice based on MircoProfile and run both in the OpenLiberty development mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages