You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _docs/en/http-stubs.md
+37-24Lines changed: 37 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -13,50 +13,63 @@ The same technique is also called mock service or service virtualization in the
13
13
14
14
The HTTP Stubs feature in API Test Base is powered by [WireMock](http://wiremock.org/).
15
15
16
-
## A quick play
16
+
## A Quick Play
17
17
Let's play with an HTTP stub quickly.
18
18
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
+

23
+
24
+
Click `+ Stub` button. On the stub edit view, enter URL `/some/thing` and response body `Hello!`.
21
25
22
26

23
27
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!`.
25
29
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.
27
31
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.
29
34
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
+

31
36
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.
33
39
34
-

40
+

35
41
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`.
38
44
39
-

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.
40
50
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).
43
52
44
-

53
+
More details follow.
45
54
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.
50
59
- 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).
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.
0 commit comments