dart-mock

Mocking with Dart

白昼怎懂夜的黑 提交于 2019-12-23 03:42:17
问题 I've been trying to get my head around the mocking library in dart, but it seems I've still not got it. In my library, I have an HTTP request to an external resource, which I would like to mock as to not rely on the external resource all the time. The main class in my library looks like this: SampleClass(String arg1, String arg2, [http.Client httpClient = null]) { this._arg1 = arg1; this._arg2 = arg2; _httpClient = (httpClient == null) ? http.Request : httpClient; } So I have prepared my

Mocking HTTP response with Dart

丶灬走出姿态 提交于 2019-12-12 14:34:04
问题 I have been working on a new API wrapper and don't want to be calling the API every time my unit tests run. So as described here, I'm mocking it. I initially thought there was something wrong with the way I'm mocking it, but it seems the problem is elsewhere. What I'm trying to accomplish is very simple. When my unit test run, I would like to return a value as if I had gone out to get the information from the external API I'm integrating with. I initialise my class with http.Client as an