VirgilChen97 / Vblog

A modern, multi-user Markdown blog system
30 stars 2 forks source link

Unit tests are needed to help with the multi-coder cooperation #2

Open pete965 opened 4 years ago

pete965 commented 4 years ago

Hi Virgil,

I have tried the online demo and I think this is an interesting project. Also, I have read some of the code and have some personal improvement suggestion coming out. The most important one, I think, is to write a set of unit tests to assist the cooperation. For spring based project, because of the auto-wiring, service test may encounter the problem of the auto-injection of the spring bean. So, choosing a suitable testing strategy is a very important issue for the developers to consider. I have two suggestions for you. The Jmockit Framework can be included to assist the service test because it can mock the auto-wiring beans and bring us a fast speed because the tests don't rely on the spring container's start-up. Another way is to introduce simple spring based test which rely on the container's start-up. This strategy is good if the container doesn't consume much time for each start-up. Some annotations need to be added to the unit test class to declare that this test need the container to start.

Regards, Boyang Sun

VirgilChen97 commented 4 years ago

Good suggestions!

Now unit tests are not available in this repo because some tests are depend on test database which can not be access remotely. If I included them in the repo they will break CI/CD pipeline.

I will add unit test to the repo as soon as I figured out how to setup test database in Github Actions. Thank you very much!

pete965 commented 4 years ago

Maybe you need a online RDS database and config it in Github repo. Or you may try DbFit test framework to assist you with this problem. DbFit can help you to construct a simple database environment for every unit test based on some simple configuration and other related files. This is also essencial in the unit test of the whole project, which is, for example, a unit test for a specific service should only test the bussiness logic of this service, not the db operation or any other things. This will ensure when you update the code, the unit test can help you most to avoid other modules to be affected, whichever they are services or db operations.

When you are ready to add unit test, I think I can do some help.

Regards!

VirgilChen97 commented 4 years ago

Thanks! I'll consider these options.