WireMock.Net is a tool which mimics the behaviour of an HTTP API, it captures the HTTP requests and sends it to WireMock.Net HTTP server, which is started and as a result, we can setup expectations, call the service and then verify its behaviour.
When Should We Use WireMock.Net?Below are three situations when we should use WireMock.Net:
1.HTTP Dependencies Not Ready
An engineering team needs to implement a feature which uses an HTTP API that is not ready, this occurs often in an microservice based architecture.
To avoid engineering waste, you can mimic the behaviour of the HTTP API using WireMock.Net and then replace the call to WireMock.Net API to the actual API.
2.Unit Test classes which use HTTP APIs
Scenario: Class A -> depends on -> Class B -> depends on -> HTTP API
We want to unit test for Class A.
Option1: Replace depend Class B with a MockObject when unit testing Class A.
However, if the API client is written by you, using a mock object is not a good choice because it does not allow us to verify that our code can communicate with the HTTP API.
Sociable Tests
Therefore, Class A & Class B should be tested as one unit and as a result we can verify that the correct information is send to the HTTP API and ensure that all legal responses can be processed by both Class A & Class B.
3.Integration or End-to-end tests using external HTTP APIs
Dependency Down
External HTTP API cannot initialise into a known state before the tests are run. Therefore, we cannot write tests which use the data returned by the external HTTP API, as it can differ.
Slow tests
External HTTP API takes longer than getting the same response from WireMock.Net and we cannot use a short timeout because the test will fail, when the call is timed out.
API Requests Blocked
Wrong network connection, the API request which does not come from a known IP address is blocked.
To write fast and consistent tests for HTTP APIs we should be using WireMock.Net. However, WireMock.Net cannot guarantee that our application is compatible with the consumed HTTP API.The WireMock.Net tests will ensure
Note: this page is based on https://github.com/AdriseYounis/WireMock.Net/blob/master/README.md
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4