I need to write simple http client. It could be great to have unit tests for my class. But I don't know how to write proper and testable class.
For example, I have a client like this:
class HTTPClient
{
public:
HTTPCLient(const std::string& host, const std::string& port): session(host, port) {}
void send()
{
session.sendRequest(someRequest);
Response response = session.receiveResponse();
// ...
}
private:
SomeLibrary::ClientSession session;
};
How to test send
method (that I really send what I want)? I can't mock it. I can write that HTTPClient
receives SomeLibrary::ClientSession
object in constructor (in test I would pass mock) but is it good design? I think that the way of implementing of session etc. should by hidden in my class.
Do You have any idea?