Testing is the critical part in the software development. This week, I added unit test cases and continuous integration on my LinkChecker-CmdLC project.
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. 😆