7 ms·
In that setup, how do you write a test which acts against a mock version of your API client (a static function in your proposal?)
by turdprincess 1y ago
In that setup, how do you write a test which acts against a mock version of your API client (a static function in your proposal?)
- nrook 1y agoRun a fake version of the API server, and then connect the real client to it. It is usually a mistake to make the "unit" of your unit test too small.
- kdps 1y agoIn this case, API does not refer to client/server. The API of the aforementioned static class is the set of its methods and their signatures.
- beders 1y agoyeah, I wouldn't recommend trying to do this with pure Java but you could pass around method handles for that purpose. You certainly would want to use an `interface` and that means you need an object. It could be an object that has no fields though and receives all data through its methods. But it does go against the spirit of objects: You want to make use of `this` because you are in the land of nouns.
- MrDarcy 1y agoIn Go at least you simply define an interface and use it as the receiver then inject whatever mock object you want. The mock itself may simply be a new type defined in your test case.
- btreecat 1y agoGenerally, avoid mocks. Run a copy of the server in a container, run client E2E tests against it.