Comments (9)
Yeup that sounds reasonable! My recommendation would be to mock the generated gRPC client instead, since you can be reasonably sure that the generated code uses gRPC-dart correctly, and that gRPC-dart itself is tested. This makes the complicated harness completely unnecessary.
To do this using mockito:
// Assuming you're testing a generated client called LoginClient
class MockLoginClient extends Mock implements LoginClient {}
test('login request', () async {
final mockClient = MockLoginClient();
var expectedResp = new LoginResp();
loginResp.token = 'Token';
loginResp.success = true;
when(mockClient.loginRequest(any)).thenAnswer((_) => Future.value(loginResp));
var loginReq = new LoginReq();
loginReq.serverAddr = '127.0.01';
loginReq.imei = 350..;
loginReq.language = 'EN';
loginReq.password = 'Password';
loginReq.userName = 'UserName';
var realResp = await mockClient.loginRequest(loginReq);
expect(realResp, expectedResp);
});
Does that make sense?
from grpc-dart.
Thanks for your response.
but I got this error
type 'Future' is not a subtype of type 'ResponseFuture'
Any idea how I could solve this?
from grpc-dart.
I've posted workaround for mocking client responses: google/protobuf.dart#162 (comment)
from grpc-dart.
Are you writing a test to test your own GRPC Client?
client_test.dart is really structured to test the inner workings of the client / server communication down to the Http2 transport layer. If you want to go down to this level of testing you will still have to encode the LoginResp message to a StreamMessage for this to work. The serializations are usually generated as part of the protobuf tool.
In general, if you're writing your own client you likely don't want to go down to this level, which is really testing how grpc-dart works (which already has tests).
Does that make sense?
from grpc-dart.
I don't want to test GRPC client.I wrote an application with dart(client side) and go(server side) and for test I don't want to connect directly to db and get response.I want to write mock server and get response from this mock server.
from grpc-dart.
It looks like ResponseFuture is an implementation detail of the client. I've opened the above issue on the actual code generator to replace it with Future in generated Client signatures.
In the meantime as a workaround you could replace ResponseFuture with Future in the generated client.
from grpc-dart.
from grpc-dart.
Can you think of any way to work around it? To create ResponseFuture mock? I failed to do it :(
from grpc-dart.
Not that I can think of. ResponseFuture is very much an implementation detail -- its entire extension interface is private and it doesn't expose a way to create an already completed future (like Future.value).
If you attempt to mock ResponseFuture you would have to mock the relevant calls to Future, which I don't happen to know (probably just then
but I'm not sure)
from grpc-dart.
Related Issues (20)
- [help needed] Use generated service methods to process gRPC-web data. HOT 2
- Is ResponseStream.cancel supposed to update ServiceCall.isCancelled? HOT 1
- Repeated requests in a loop with a timeout. GRPC DEADLINE_EXCEEDED -> Next request HTTP/2 error: (errorCode: 1) HOT 5
- Support .map() that returns ResponseStream instead of Stream HOT 4
- Reconnect logic HOT 7
- `timeline_test` failure on Windows. HOT 3
- Track some specific request using ClientCall HOT 3
- Replace `package:archive` use by `dart:io` and `DecompressionStream`
- #703 broke grpc interop testing HOT 7
- Is it possible to expose stream state to the app? It's vital for tracking http2 requests and make appropriate reconnect logic etc.... HOT 19
- Question: Best practice for using ClientChannel HOT 4
- Question: How to implement a ClientInterceptor with async body
- Migrate off legacy JS/HTML apis HOT 7
- Grpc connect to some site and fail on some HOT 4
- Streaming issue on web only HOT 1
- Creating GrpcOrGrpcWebChannel always throws `UnsupportedError('not supported by gRPC-web') HOT 1
- ClientChannel has no way to trigger a connection to the server if no RPC is being invoked HOT 5
- Error connecting: Unsupported operation: Socket constructor (WASM) HOT 1
- Awaiting ResponseFuture.headers hangs indefinetly for not implemented services HOT 1
- Exceptions thrown without stack traces HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-dart.