Unit test | Continuous Integration

Testing is the critical part in the software development. This week, I added unit test cases and continuous integration on my LinkChecker-CmdLC project.

To better build and manage my project, I spent some time to convert my project to a maven project before I started writing some unit test cases using JUnit.

A maven project has standard directory layout, as well as a pom.xml file managing dependencies and plugins. My project looks like this. All source files are in the src/main/java folder, while test sources are in src/test/java folder. This avoids file path issues.

The hardest part of all test cases was mock a Http Connection, which required to simulate network responses. Mockito was the popular tool to do the mock in Junit, therefore my original try was using Mockito. After failing to implement mock network connection many times, I got help from my classmate. He suggested me to use powerMockito. Here is my final code.

Once you write test cases, the good practice is using a test coverage tool to check your test cases coverage rate.

In addition, I set a continuous integration check for my project using Github Action. It is a very useful tool to manage a project, especially a big and fast moving project with lots of contributors. You can set various test checks base on actions. You can set the checks running on different operate systems, such as windows, ubuntu, etc. I set 6 jobs in the project workflow, that means once a pull request or a push is submitted, github will do these checks for me to ensure the project integration.

Besides Junit, I know that Jest is another popular testing framework. So, I tried to write test cases using Jest to my classmate project. (See pull request)

I know I still need to write more test cases to be proficient in JUnit and Jest, but I am already on the way. I really like this course. 😆

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s