Search code examples
c++curlhttpslibcurlgoogletest

How to test HTTPS requests (SSL) through CURL in gtest?


I am going to send HTTPS requests through curl and would like to test it using gtest. How should I proceed with it?


Solution

  • Most probably you will need to introduce a wrapper around curl library you use and mock it for the most part (see gmock intro). This will help you to test the interactions with the library itself. Given no HTTPS request will be really performed, the tests will be reliable, fast and small.

    Above technique will not help you to actually perform HTTPS requests and validate this pat of you code. However, if the library you use works as expected (it should), you should test your interaction with the library rather than the library itself (it should be tested on its own).

    If you require some integration tests (i.e. tests that consist of you code interacting with server side), gtest wouldn't be my weapon of choice. I was using behave framework (Python) where you could set up your own HTTPS server (prototyping it in Python would be much easier) and test your application against this stubbed HTTPS server.