This project was created to contain resources to support my notes on unit tests in java.
PLEASE NOTE:
- No proprietary source code has been used in this repository.
- The test object classes are abstract in their purpose, purely for illustrative purposes, and in no way connected to any production code.
- The test libraries used - as well as the frameworks used as examples - are public domain.
This project consists of several modules, each of which represents a specific 'step' in testing.
The libraries used fall into two categories:
- testing libraries:
- application frameworks, to illustrate testing using these frameworks
Simple class testing, a very simple test of a single class, without any framework.
You will see modules step01-<xxx>
, please refer to each module's README.md
for information.
Testing a service class, with collaborators.
This kind of test is very important, and shows how and why we need to use Mockito to create 'mock' collaborators and stubbing them to simulate their desired behaviour for the test cases.
You will see modules step02-<xxx>
, please refer to each module's README.md
for information.
Testing a service class, with collaborators, and interaction with an external REST service.
This kind of test is very important, it shows how we can use WireMock to test our REST-client based classes.
You will see modules step03-<xxx>
, please refer to each module's README.md
for information.
You need Java 17 and Apache Maven to build this project.
Feel free to install them as you like best, a suggestion is to use Homebrew and SDKMAN
Open a terminal and run
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Open a terminal and run
curl -s "https://get.sdkman.io" | bash
I also suggest you edit your ~/.sdkman/etc/config
file, and add/update the entrysdkman_auto_env=true
Open a terminal and run
sdk install java 17.0.7-tem
sdk default java 17.0.7-tem
Open a terminal and run
brew install maven
You can build the project by running the following command in a terminal, from the project's root folder:
mvn clean install
(if you want to build the Javadoc as well)
mvn clean install -Pjavadoc
After the build is completed, in each module's target/site/apidocs
folder you can find the generated javadoc.
After the build is completed, in each module's target/site/jacoco
folder you can find the test coverage report.