C J
C J

Reputation: 607

How to test gRPC APIs?

I have been assigned to test a gRPC API (written in Golang) but I don't know how to go about testing it and I couldn't find any tutorials online for this type of testing. The only method that I can think of is to write unit tests to test the methods themselves but I would like to also test it with a client. For example, I have tested REST APIs in the past using JMeter as a client to send requests and verify the response data. Is there a method for testing gRPC APIs with a client or is unit testing the only way?

Upvotes: 21

Views: 49074

Answers (8)

alvaropgl
alvaropgl

Reputation: 850

If you are using JMeter for load testing, maybe ghz.sh suits your needs.

You only need to provide the .proto file and the data

ghz --insecure \
  --concurrency=50 \
  --total=200 \
  --proto ./greeter.proto \
  --call helloworld.Greeter.SayHello \
  -d '{"name":"Joe"}' \
  0.0.0.0:50051

Caution, by default it does 50 concurrent request (200 in total). The example assumes you have a grpc service running at 0.0.0.0:50051 and defined in the greeter.proto like:

package helloworld;

service Greeter {
    rpc SayHello (HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
  string name = 1;
}

Upvotes: 0

Rom Haviv
Rom Haviv

Reputation: 188

Postman just published they have grpc in beta :

https://blog.postman.com/postman-now-supports-grpc/

I tested it just now and it worked perfectly for me 👍🏻🙂

grpc postman

Upvotes: 5

Prasanna Mondkar
Prasanna Mondkar

Reputation: 131

For anyone who stumbles upon this thread ... All the previous answers have already provided good tools. We used BloomRPC & Kreya in our team (individual choices).

What I want to add is this gRPC Ecosystem Page. It contains a curated lists of all related tools. There are other GUI test tools (see GUI section), or Load testing, benchmarking tools (Testing)

https://github.com/grpc-ecosystem/awesome-grpc

PS : I'll be honest, I have not able to check all tools besides BloomRPC & Kreya.

Upvotes: 4

Erik Araojo
Erik Araojo

Reputation: 91

Since you mentiond you've done testing before with JMeter, I assume that you're looking for an external test client that can call the gRPC service. There are several that you can use. The common ones are

With those 4 clients, you can dynamically call gRPC services. However, if you are looking a test client that can also do load testing, Fint is the one you will need.

Upvotes: 5

Manuel Allenspach
Manuel Allenspach

Reputation: 12745

If you are searching for a tool like Postman, there is also https://kreya.app. With it, you can call your gRPC services and view the responses.

Disclaimer: I'm one of the authors of Kreya.

Upvotes: 14

wannabepro
wannabepro

Reputation: 54

You can also try this command line tool, evans, for testing gRPC

Upvotes: 2

Pram
Pram

Reputation: 2501

Well, I was in search for a client like Postman, then i found bloomrpc, which helps in calling grpc services. But i am not sure if it serves your purpose, if you are looking for a tool like jmeter.

Upvotes: 16

Shettyh
Shettyh

Reputation: 1216

There can be two type of testing.

  • Testing just the implementation of the gRPC method by ignoring the networking

    this question answers this aspect of the testing. By just writing the unit test for the RPC method

  • If you want to test both the implementation and the gRPC networking aspects as well then you need write the gRPC client for the service you want to test.

Here a code snippet about creating a gRPC client

// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
// Execute RPC you want to test
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})

Check here for complete code example

Upvotes: 2

Related Questions