Three good gRPC testing tools

Recently, we are using Golang to implement microservices, and the communication interface is gRPC. In addition to writing client-side tests in third-party languages supported by gRPC, are there any good tools to verify the interface implemented by gRPC? This year, we saw that Postman announced that it started to support gRPC, so I believe that you are not too unfamiliar with Postman tool, after all, we rely on this tool to test Websocket or RESTful API. This article not only introduces Postman, but also a set of CLI tools grpcurl and a set of GUI tools grpcui is also not bad to use, the latter two sets are developed by the same company FullStory out of the project, the following to introduce one by one.

Testing gRPC service

I have written a test example version, the gRPC definition proto file can be viewed from here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
syntax = "proto3";

package gitea.v1;

message GiteaRequest {
  string name = 1;
}

message GiteaResponse {
  string giteaing = 1;
}

message IntroduceRequest {
  string name = 1;
}

message IntroduceResponse {
  string sentence = 1;
}

service GiteaService {
  rpc Gitea(GiteaRequest) returns (GiteaResponse) {}
  rpc Introduce(IntroduceRequest) returns (stream IntroduceResponse) {}
}

grpcurl

I believe we have all used the powerful curl tool, and grpcurl can be thought of as a gRPC version of curl. The installation is very simple, you can find the OS version you want on the Relase page, or if you are a Go developer you can install it via go install.

1
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

MacOS environment can be installed via Homebrew.

1
brew install grpcurl

Or you can run it through Docker.

1
2
3
4
# Download image
docker pull fullstorydev/grpcurl:latest
# Run the tool
docker run fullstorydev/grpcurl api.grpc.me:443 list

First set up the test environment, then you can test the 8080 port on the local side.

1
2
3
4
$ grpcurl -plaintext localhost:8080 list
gitea.v1.GiteaService
grpc.health.v1.Health
ping.v1.PingService

Since there is no SSL certificate on the local side, please add the -plaintext parameter to use it, the detailed parameters can be checked by -h, and then type the first test interface.

1
2
3
4
5
grpcurl \
  -plaintext \
  -d '{"name": "foobar"}' \
  localhost:8080 \
  gitea.v1.GiteaService/Gitea

The results obtained are as follows.

1
2
3
{
  "giteaing": "Hello, foobar!"
}

If you have added Health Check to your service, you can use the following command directly.

1
2
3
4
5
grpcurl \
  -plaintext \
  -d '{"service": "gitea.v1.GiteaService"}' \
  localhost:8080 \
  grpc.health.v1.Health/Check

The results obtained are as follows.

1
2
3
{
  "status": "SERVING"
}

If the service has support for Server Streaming RPC, it is also the same usage.

1
2
3
4
5
grpcurl \
  -plaintext \
  -d '{"name": "foobar"}' \
  localhost:8080 \
  gitea.v1.GiteaService/Introduce

You can see that Server responds with two messages.

1
2
3
4
5
6
{
  "sentence": "foobar, How are you feeling today 01 ?"
}
{
  "sentence": "foobar, How are you feeling today 02 ?"
}

grpcui

In addition to the above grpcurl, the same team has also released grpcui, a gRPC testing tool with a Web UI. grpcui is installed in the same way as grpcurl, so there is no need to explain it here. grpcui also supports all RPC functions, including streaming, etc. The GUI console can be started with the following command line.

1
grpcui -plaintext localhost:8080

grpcui

This page has already helped to prepare the Service and the Method that can be used. You don’t need to know which Method is provided by any service, it’s very convenient, and the Request Data on the screen will change when you select different Service and Method.

grpcui

After filling out the Request Form and switching to Raw Request (JSON), you can see the JSON Format data.

grpcui

After clicking invoke, you can see the following result.

grpcui

The results of testing Streaming are as follows.

grpcui

Postman

I believe you are still most familiar with Postman, testing any service can not be separated from this tool, but also very happy to see the support of gRPC Beta version in January this year, open the software, press the upper left corner of New you can see the following interface, select gRPC Request.

Postman

The API on the left can write the proto data of all the services into it.

Postman

Then you can select it by New Request and run invoke.

Postman

The results of testing Streaming are as follows.

Postman

Thoughts

The grpcurl CLI tool can be used in Linux environments where there is basically no desktop, so it is recommended. However, Postman needs to write the proto data manually before it can be tested. So I strongly recommend using grpcui to read the proto information directly and dynamically, and turn the information into Request Form to reduce the time of querying data attributes.

Reference

  • https://blog.wu-boy.com/2022/08/three-grpc-testing-tool/