Writing a React Component Test with Jest and Testing Library

Goals render a React component in a test mock HTTP/REST calls to the backend verify results achieve the above using typescript, jest and testing-library Application under Test This is our application’s shortened package.json, generated by create-react-app, adding dependencies for …​ jest testing-library typescript react dom implementations (jest-dom/react-dom) axios (for the HTTP/REST call) package.json { [..] "dependencies": { "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", "@types/jest": "^26.0.15", "@types/node": "^12.0.0", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "4.0.3", "typescript": "^4.1.2", "web-vitals": "^1.0.1", "axios": "^0.19.0" }, [..] "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, [..] } ...

June 4, 2021 · 3 min · 559 words · Micha Kops

Testing OpenAPI Swagger Schema Compliance with Java, JUnit and assertj-swagger

The OpenAPI and Swagger API description format are becoming important standards to specify API contracts for RESTful web services and the Microservices trend pushes the need for such contracts even further. Therefore arises the need for software architects, testers and developers to write tests to verify if an exposed API follows such a specified contract. In the following tutorial I will demonstrate a setup with Java, Maven, JUnit and the designated contract-testing-library, assertj-swagger that verifies the validity of such a contract exposed by a Spring Boot application against a local stored definition. ...

August 31, 2018 · 5 min · 871 words · Micha Kops

Writing BDD-Style Webservice Tests with Karate and Java

There is a new testing framework out there called Karate that is build on top of the popular Cucumber framework. Karate makes it easy to script interactions with out web-services under test and verify the results. In addition it offers us a lot of useful features like parallelization, script/feature re-use, data-tables, JsonPath and XPath support, gherkin syntax, switchable staging-configurations and many others. In the following tutorial we’ll be writing different scenarios and features for a real-world RESTful web-service to demonstrate some of its features. ...

April 6, 2017 · 12 min · 2549 words · Micha Kops

Creating Microservices with Bootique

When it comes to writing microservices in Java, plenty of tools and frameworks exist. In the following tutorial, I’d like to demonstrate another minimalistic framework called Bootique by implementing a simple microservice exposing its functions either as a RESTful web-service or as a runnable command executed using the command line. Bootique Command Line Dependencies Using Maven here, we’re adding the following elements to our project’s pom.xml: Bootiques Bill of Materials as dependency management: bootique-bom Bootique Jersey for our REST service: bootique-jersey Bootique Logback for logging: bootique-logback Maven Shade Plugin to assemble our fat-jar ...

September 18, 2016 · 6 min · 1070 words · Micha Kops

Mocking HTTP Interaction with Java, JUnit and MockServer

When writing tests for our software components sometimes we need to mock external services based on the HTTP protocol, might it be a RESTful web-service, an XML-RPC call or a simple GET request to some web-server. In the following short tutorial I’d like to demonstrate how to create a mock HTTP server for testing and how to bootstrap and bind it to the life-cycle of a classical build-management tool like Maven. ...

January 5, 2016 · 4 min · 821 words · Micha Kops

Creating REST Clients for JAX-RS based Webservices with Netflix Feign

For us developers there plenty of libraries exist helping us in deriving and generating clients for existing RESTful web-services and I have already covered some of the in this blog (e.g. the JAX-RS Client API). Nevertheless, I’d like to share my experience with another interesting lightweight library here: Netflix Feign. Feign offers a nice fluent-builder API, a rich integration for common libraries and APIs like JAX-RS, Jackson, GSON, SAX, JAX-B, OkHttp, Ribbon, Hystrix, SLF4J and more and last bot not least, it is setup easy and the service contracts are specified using interfaces and annotations. ...

October 22, 2015 · 6 min · 1138 words · Micha Kops

Creating and Providing HipChat Integrations with Atlassian Connect, Nodejs and Express

HipChat is Atlassian’s alternative to Slack and its solution to team collaboration chats. Atlassian Connect offers developer tools to bootstrap applications, connect to Atlassian’s cloud products with easy and in combination with HipChat’s REST APIs allows us to write integrations for such a chat server in no time. In the following tutorial I’d like to show how to write an integration within a few steps using Atlassian Connect, Node.js and Express and how to connect the integration to a HipChat server. ...

August 18, 2015 · 17 min · 3495 words · Micha Kops

Integrating Swagger into a Spring Boot RESTful Webservice with Springfox

Spring Boot allows us to create RESTful web-services with ease, Swagger specifies a format to describe the capabilities and operations of these services and with Swagger UI it is possible to explore our REST API with a nice graphical user interface in our browser. Springfox is a project that aims at creating automated JSON API documentation for API’s built with Spring and is used in the following tutorial to integrate Swagger into a sample application. ...

July 1, 2015 · 7 min · 1418 words · Micha Kops

Documenting RESTful Webservices in Swagger, AsciiDoc and Plain Text with Maven and the JAX-RS Analyzer

A variety of different tools exists to help us analyze RESTful web-services and create documentations for their APIs in different formats. In the following tutorial I’d like to demonstrate how to document an existing JAX-RS web-service in multiple formats like Swagger, AsciiDoc or Plain Text using Maven, the JAX-RS Analyzer and the JAX-RS Analyzer Maven Plugin. The JAX-RS Analyzer gathers its information not only by reflection like most other tools but also by bytecode analysis and therefore does not require us to add special annotations for documentation to our code. ...

June 16, 2015 · 6 min · 1119 words · Micha Kops

Java EE: Setting up and Testing Form-Based JDBC Authentication with Arquillian and Maven

Especially when it comes to testing, setting up a decent environment for a secured Java EE web application isn’t always an easy thing to do. In the following tutorial I’d like to demonstrate how to create a secured web application using form-based authentication and a JDBC realm to fetch users and roles and how to run the application in an embedded container for testing and development. Additionally I’d like to show how to write and run integration tests to verify the security setup using a setup of Maven, Embedded GlassFish, Arquillian, jUnit and rest-assured. ...

December 21, 2014 · 14 min · 2822 words · Micha Kops