Skip to content

Commit 685c1b6

Browse files
committed
update HTTP Stubs doc
1 parent 365cde7 commit 685c1b6

7 files changed

+37
-24
lines changed

_docs/en/http-stubs.md

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,63 @@ The same technique is also called mock service or service virtualization in the
1313

1414
The HTTP Stubs feature in API Test Base is powered by [WireMock](http://wiremock.org/).
1515

16-
## A quick play
16+
## A Quick Play
1717
Let's play with an HTTP stub quickly.
1818

19-
### Create a stub and load it
20-
Create a temp test case. Go to its `HTTP Stubs` tab and click `+ Stub` button. On the stub edit view, select `POST` method, enter URL `/some/thing`, select request body pattern `Equal to JSON`, enter request body `{ "a": "b" }`, and enter response body `Hello!`.
19+
### Create a Stub
20+
Open the Mock Servers view, select the `Manual` mock server, and select its HTTP Stubs tab.
21+
22+
![Quick Play - Manual Mock Server](../../screenshots/http-stubs/quick-play-manual-mock-server.png)
23+
24+
Click `+ Stub` button. On the stub edit view, enter URL `/some/thing` and response body `Hello!`.
2125

2226
![Quick Play Stub Details](../../screenshots/http-stubs/quick-play-stub-details.png)
2327

24-
The meaning of the stub is that when an HTTP POST request is sent to the mock server with URL `http://<APITestBaseHost>:<MockServerHTTPPort>/some/thing` (like http://localhost:8092/some/thing) and request body `{ "a": "b" }`, the mock server will return an HTTP response with status code 200 and response body `Hello!`.
28+
The meaning of the stub is that when an HTTP GET request is sent to the `Manual` mock server with URL `http://<ApiTestBaseHost>:<MockServerHttpPort>/some/thing` (like http://localhost:8094/some/thing), the mock server will return an HTTP response with status code `200` and response body `Hello!`.
2529

26-
The mock server is embedded in the API Test Base instance and is started when API Test Base starts.
30+
The default port number of the `Manual` mock server is `8094`, and it can be changed under the `Settings` tab of the mock server.
2731

28-
To use HTTPS with the mock server, you can just use URL `https://<APITestBaseHost>:<MockServerHTTPSPort>/some/thing`.
32+
### Test the Stub
33+
Open a new tab in your browser, and go to `http://localhost:8094/some/thing`, and you'll see response body `Hello!` on the page.
2934

30-
The mock server has a default HTTP port number 8092 and a default HTTPS port number 8093. Both can be changed in the `<ATB_DATA_DIR>/config.properties`.
35+
![Quick Play Stub Invocation](../../screenshots/http-stubs/quick-play-stub-invocation.png)
3136

32-
To manually load the stub into the mock server, go to the test case edit view > HTTP Stubs tab, and click the `Load All` button.
37+
## Mock Server Status
38+
To know what stubs have been loaded into the mock server, or check stub request log, open the mock server Status tab.
3339

34-
![Quick Play Stub List](../../screenshots/http-stubs/quick-play-stub-list.png)
40+
![Mock Server Status](../../screenshots/http-stubs/mock-server-status.png)
3541

36-
### Test the stub
37-
Go to the `Test Steps` tab of the test case, and create an HTTP test step with method `POST`, URL `http://localhost:8092/some/thing` and request body `{ "a": "b" }`. Click the `Invoke` button to invoke the stub, and you'll see a response body `Hello!`.
42+
## Mock Servers
43+
There are two mock servers in API Test Base: `Manual`, `Auto`.
3844

39-
![Quick Play Stub Invocation](../../screenshots/http-stubs/quick-play-stub-invocation.png)
45+
### The Manual Mock Server
46+
The `Manual` mock server is used for defining and hosting ad hoc HTTP stubs. You can define HTTP stubs on the `Manual` mock server, and then immediately use/invoke it without any dependency.
47+
48+
### The Auto Mock Server
49+
The `Auto` mock server is used when running test cases which have HTTP stubs defined on them. The HTTP stubs are defined on test cases, rather than on mock server.
4050

41-
## Mock server status
42-
To know what stubs have been loaded into the mock server, or check stub request log, open the mock server page by clicking the `Mock Server` link under the `HTTP Stubs` tab of the test case.
51+
When a test case runs, the `Auto` mock server is cleared and all HTTP stubs defined on the test case are automatically loaded into the `Auto` mock server, ready to be invoked (by your API under test).
4352

44-
![Mock Server Status Page](../../screenshots/http-stubs/mock-server-status-page.png)
53+
More details follow.
4554

46-
## Use HTTP stubs in automated API testing
47-
It is easy. Create stubs in your test case like above, but no need to load them into mock server manually (via the Load All button). Every time you run the test case, below things happen automatically
48-
- On test case run start, the mock server is reset and the stubs defined on the test case are loaded into the mock server.
49-
- Mock server reset means all stubs and all stub request logs are cleared from the mock server.
55+
## Use HTTP Stubs in Automated API Testing
56+
It is easy. Create stubs in your test case under its `HTTP Stubs` tab. Every time you run the test case, below things happen automatically
57+
- On test case run start, the `Auto` mock server is reset and all the stubs defined on the test case are automatically loaded into the mock server, ready to be invoked (by your API under test).
58+
- Mock server reset means all stubs, stub request logs, scenarios, etc. are cleared from the mock server.
5059
- On test case run end, stub requests received by the mock server are checked by asserting
51-
- All stubs in the test case have been hit.
52-
- If the 'Check Hit Order' option is selected under the HTTP Stubs tab on the test case edit view, the stubs have been hit in ascending order by stub number.
53-
- All stub requests received by the mock server have been matched (i.e. each request has hit a stub in the test case).
60+
- All stubs from the test case have been hit.
61+
- If the 'Check Hit Order' option is selected under the HTTP Stubs tab on the test case edit view, the stubs from the test case have been hit in ascending order by stub number.
62+
- All stub requests received by the `Auto` mock server have been matched (i.e. each request has hit a stub from the test case).
5463

5564
## Other supported features
56-
- Setting a delay for response
65+
- **Setting a delay for response**
5766
- [Response templating](http://wiremock.org/docs/response-templating/)
5867
Use attributes of the request in the response.
5968
- [Regex matching on path and query](http://wiremock.org/docs/request-matching/#regex-matching-on-path-and-query)
6069
Use this when your client request URL contains dynamic parts.
6170
- [Stateful Behaviour](http://wiremock.org/docs/stateful-behaviour/)
62-
This is useful when you want to ensure the stubs are hit in specified order.
71+
This is useful when you want to ensure the stubs are hit in specified order.
72+
- **HTTPS stubs**<br>
73+
This is useful when your API under test can only call HTTPS dependencies.<br>
74+
The same stub can be invoked via both HTTP and HTTPS. To invoke a stub via HTTPS, simply use a different port number. `https://<ApiTestBaseHost>:<MockServerHttpsPort>/some/thing`, like `https://localhost:8095/some/thing`.<br>
75+
The HTTPS port number can be changed under the mock server's `Settings` tab.
Binary file not shown.
128 KB
Loading
Loading
Loading
Loading
-31.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)