paint-brush
Introduction to gRPC Testing on a Real Projectby@sergeishaikin
1,200 reads
1,200 reads

Introduction to gRPC Testing on a Real Project

by Sergei ShaikinJune 28th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In this story, I will demonstrate on an actual project how to test a service that communicates through the gRPC framework. You can use two different ways to test the service: the command line or the GUI. I hope this part is most interesting for a lot of people.
featured image - Introduction to gRPC Testing on a Real Project
Sergei Shaikin HackerNoon profile picture

In this story, I will demonstrate on an actual project how to test a service that communicates through the gRPC framework, and you can add a new row to your resume.


First, I would like to thank my colleagues who created and improved this project. The creator is the excellent developer Mikhail Petrov. And no less remarkable programmer

Alexander Smyslov improved this project.

Preparation

In the first step, we will prepare our environment with some commands. I am showing it for the operation system MacOS. If you already have Python on your PC, you can skip those three commands.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
brew unlink python && brew link python

The next two commands are necessary for the project. We are installing two packages for working service.

pip install grpcio-tools
pip install grpcio-reflection

Installation

In the second step, we will install our project on the local machine. You need to perform those commands in your terminal:

git clone https://github.com/MikhailPO/grpcExampleService
cd grpcExampleService
find . -name "*.sh" -exec chmod +x {} \;
./generate_file.sh
./install.sh
./start.sh

We are cloning the project to the local machine. And we are moving to the folder grpcExampleService


After that, we make our files executable. Generate all necessary files. Install them. And start the service. That’s it. Our service is running and ready to test.

Instruments for Testing

For the testing, you can use two different ways:


  • CLI instruments

  • GUI instruments


For me, it is better to use GUI instruments because it is more comfortable. But the CLI instruments are more suitable if you need to check your service directly on the server because you are able to execute commands quickly, and it requires fewer computing resources.

CLI instruments

There are lots of CLI instruments for testing gRPC, and I will list some of them here.


  1. grpcc - flexible command-line client for any gRPC server

  2. grpc_cli - gRPC command line tool

  3. grpc-client-cli - interactive gRPC client


Of course, this is not a complete list. I just showed only the ones I like. And if you launch, for example, grpc-client-cli, you can interact with him like this:


GUI instruments

Also, there is a list of GUI instruments for testing gRPC:


  1. Kreya - the ultimate gRPC and REST client

  2. Postman - the well-known and most popular tool, but registration is required to use gRPC

  3. BloomRPC - one of the first GUI clients, but now it rests in peace

  4. Insomnia - the easy way to design, debug, and test APIs, but there are better clients for gRPC


Of course, this is my personal opinion based on my own experience with these GIU clients.

And I am sure that there are some more GUI clients, and I'd love to hear from you in the comments about those clients.

Testing

I hope this part is the most interesting for a lot of people. Our service already started, and we can try it to test. I will show it using Kreya. We need to create a project for the first step after launching the GUI client.

Give him the name and select a folder where this project will be.

Select gRPC as a type of API that we will be using.

In the next step, you have three options to choose from: Server reflection, Proto files, and Proto file descriptor set. Our project has already implemented server reflection, so we choose this option.

And also, we need to enter the endpoint:

http://localhost:50051

That’s it. Our GUI client has been launched and configured. We can work with our service using Kreya.


You will see the GrpcExampleService folder, which already contains three APIs (AddClient, GetClientByLogin, and GetClients). You are able to send each API immediately because the API body structure is loaded automatically. And it is not necessary to refer to the documentation for clarifications.

Server reflection

Server reflection is a very useful thing for testers because you don't have to take care of a lot of Jenkins CI/CD processes. You just need to update the GIU client, and you will be able to see all the changes made by your developers. And, of course, in our project, this possibility is implemented.

First, you need to switch to another branch of our project. Go to the terminal. Stop the service with the Ctrl+C command. And switch to the branch ModifyClientById:

git checkout ModifyClientById


Re-generate our files, install them, and start our service again.

And now we can enjoy all the charm of the server reflection function. Go back to our GUI client Kreya.


For now, we must do only one important thing. We need to refresh.

After refreshing, we are able to use all changes made by developers. In our case, it is a new API called ModifyClientById.

Instead of a Conclusion

In this project, you will test the service a bit and get some idea about the gRPC technology. And, of course, the testing of this service does not end there. Now that you know how the service works, you can continue your own research and create your own test cases because there is a full-fledged database here. It is deployed through a SQL light. You can connect to it and check the correctness of the recording of all information. And also, you can check this service for SQL injection.


I hope you liked my article and got a helpful experience in testing gRPC.


Photo by Liam Drinan on Unsplash