logo
logo
Sign in

Unit testing in go with MySQL

avatar
Canopas
Unit testing in go with MySQL

Tests are stories we tell the next generation of programmers on a project. — Roy osherove


Unit test is the first most essential part of software testing, which focuses on small elements of software design.


Always put testing as a priority in the queue. After all, QUALITY is everyone’s responsibility.


Suppose you are developing a music app, your APIs are in golang and you want to test those APIs.


This API returns JSON objects of music from the MySQL database.


Unit test for music API


1. Initialize unit test data

2. Setup gin router for test APIs

3. Generate expected data

4. Create a common API request structure that can be used for all APIs.

5. Write a common test for all APIs.

6. Run the unit test using the below command.



I have divided the process of writing the unit test into some small parts for easy understanding.


For a step by step guide, check out the original post.

collect
0
avatar
Canopas
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more