mirror of https://github.com/grpc/grpc-java.git
Explain why client stub mocking is discouraged (#5796)
This commit is contained in:
parent
bc2e1764f6
commit
9b4c958201
|
|
@ -107,6 +107,19 @@ We encourage users to leverage `InProcessTransport` as demonstrated in the examp
|
|||
write unit tests. `InProcessTransport` is light-weight and runs the server
|
||||
and client in the same process without any socket/TCP connection.
|
||||
|
||||
Mocking the client stub provides a false sense of security when writing tests. Mocking stubs and responses
|
||||
allows for tests that don't map to reality, causing the tests to pass, but the system-under-test to fail.
|
||||
The gRPC client library is complicated, and accurately reproducing that complexity with mocks is very hard.
|
||||
You will be better off and write less code by using `InProcessTransport` instead.
|
||||
|
||||
Example bugs not caught by mocked stub tests include:
|
||||
|
||||
* Calling the stub with a `null` message
|
||||
* Not calling `close()`
|
||||
* Sending invalid headers
|
||||
* Ignoring deadlines
|
||||
* Ignoring cancellation
|
||||
|
||||
For testing a gRPC client, create the client with a real stub
|
||||
using an
|
||||
[InProcessChannel](../core/src/main/java/io/grpc/inprocess/InProcessChannelBuilder.java),
|
||||
|
|
|
|||
Loading…
Reference in New Issue