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

Using JUnit 5 Parameterized Tests, Argument Sources and Converters

With JUnit 5 the possibilities to write parameterized tests have changed and improved a lot. The following short overview covers all new types of possible parameter sources for JUnit 5 tests as well as the new conversion API for test arguments. In addition we’re showing how parameterized tests were written in JUnit 4. Figure 1. Running JUnit5 in IntelliJ About We will be covering all available types of parameter sources in the following sections – all that you need as a prerequisite is Java ™, Maven and a few minutes of your time. ...

August 19, 2017 · 9 min · 1781 words · Micha Kops

Template Driven Test POJO Generation with Fixture Factory and Java

In our tests we often need to create a bunch of test-objects that are populated with random-data. This data needs to follow specific rules as identifiers need to be unique or must be incremented, string-properties must follow special conventions and so on. In the following short tutorial I will demonstrate how to generate such test data using the Fixture Factory library. Figure 1. Fixture Factory and JUnit...

June 20, 2017 · 8 min · 1689 words · Micha Kops

LDAP Testing with Java: ApacheDS vs Embedded-LDAP-JUnit

When writing applications that interchange information with LDAP directory services there is always the need to write integration tests for these components and services. Therefore we need a the possibility to start-up an embedded LDAP server, fill it with test-data and control its life-cycle during the test-phases. In the following tutorial I’d like to demonstrate two candidates that fulfil this purpose, the ApacheDS test integrations and a small library named embedded-ldap-junit. ...

July 4, 2016 · 5 min · 942 words · Micha Kops

Continuous Delivery with GitHub Cloud and GitHub Pipelines

Atlassian has added a continuous integration service as a new feature to their GitHub Cloud product. It’s called GitHub Pipelines and it is similar to Travis CI for GitHub offering a nice integration for continuous integration/delivery pipelines for projects hosted on GitHub. It’s still in the beta phase and requires a sign-up but nevertheless I’d like to demonstrate the current state of this service and how easy it is to add scripted pipelines to a project. ...

July 1, 2016 · 4 min · 760 words · Micha Kops

Layout Testing with Galen, JUnit and Maven

Writing tests not only to verify the behaviour of a web site but also the correctness of its layout especially for responsive websites is not always easy. Luckily the Galen Framework eases the task of writing layout tests for us, offering a specialized domain-specific-language to write layout-specifications, it integrates well with Selenium Grid, Sauce Labs or BrowserStack, it offers an easy way to deal with different browser sizes and responsive designs and it generates nice, detailed test reports. ...

May 16, 2016 · 7 min · 1357 words · Micha Kops

Generating JUnit Tests with Java, EvoSuite and Maven

Generating test suites for existing code allows us to verify the behaviour of an application before we’re making changes to its code base or for regression testing. In the following short tutorial I’d like to demonstrate how to derive test suites from an existing Java application using EvoSuite and the EvoSuite Maven plug-in. EvoSuite offers some nice features like running in a sandbox to avoid dangerous operations, virtual file-system and network and optimizing of different coverage criteria. ...

February 28, 2016 · 5 min · 962 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

Testing Asynchronous Applications with Java and Awaitility

Writing tests for asynchronous applications has never been much fun as we’re always struggling with the problem how to determine state changes, handle process terminations, dealing with timeouts or failures and stuff like this. Awaitility eases this process for us offering a nice DSL, rich support for languages like Scala or Groovy and an easy-to-use syntax that’s even more fun when using it with Java 8′s lambda expressions. In the following short introduction I’d like to demonstrate writing some tests different scenarios. ...

August 23, 2015 · 6 min · 1143 words · Micha Kops

Mutation Testing with Pitest and Maven

Mutation testing makes an interesting addition to the classical test coverage metrics. They seed mutations (errors) into the code, run the project’s tests afterwards and if the tests fail, the mutation is killed – otherwise it lived and we have a possible indication of an issue with our tests. In the following short tutorial. I’d like to demonstrate how to setup mutation tests with the PIT/Pitest library and Maven and generate reports. ...

May 10, 2015 · 5 min · 917 words · Micha Kops