Skip to content

Commit 8a57337

Browse files
authored
Update readme.md
1 parent 5d6b470 commit 8a57337

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

readme.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The foundation - structuring clean tests (12 bullets)
5252

5353
#### [`Section 2: Backend`](#section-2️⃣-backend-testing)
5454

55-
Writing backend and Microservices tests efficiently (8 bullets)
55+
Writing backend and Microservices tests efficiently (13 bullets)
5656

5757
#### [`Section 3: Frontend`](#section-3️⃣-frontend-testing)
5858

@@ -1053,7 +1053,53 @@ beforeEach(() => {
10531053

10541054
<br/>
10551055

1056-
## ⚪ ️2.11 Test the five potential outcomes
1056+
## ⚪ ️2.12 Check integrations corner cases and chaos
1057+
1058+
:white_check_mark: **Do:** When checking integrations, go beyond the happy and sad paths. Check not only errored responses (e.g., HTTP 500 error) but also network-level anomalies like slow and timed-out responses. This will prove that the code is resilient and can handle various network scenarios like taking the right path after a timeout, has no fragile race conditions, and contains a circuit breaker for retries. Reputable interceptor tools can easily simulate various network behaviors like hectic service that occasionally fail. It can even realize when the default HTTP client timeout value is longer than the simulated response time and throw a timeout exception right away without waiting
1059+
1060+
1061+
<br/>
1062+
1063+
**Otherwise:** All your tests pass, it's only the production who will crash or won't report errors correctly when 3rd parties send excpetional responses
1064+
1065+
<br/>
1066+
1067+
<details><summary>✏ <b>Code Examples</b></summary>
1068+
1069+
<br/>
1070+
1071+
### :clap: Ensuring that on network failures, the circuit breaker can save the day
1072+
1073+
```javascript
1074+
test('When users service replies with 503 once and retry mechanism is applied, then an order is added successfully', async () => {
1075+
//Arrange
1076+
nock.removeInterceptor(userServiceNock.interceptors[0])
1077+
nock('http://localhost/user/')
1078+
.get('/1')
1079+
.reply(503, undefined, { 'Retry-After': 100 });
1080+
nock('http://localhost/user/')
1081+
.get('/1')
1082+
.reply(200);
1083+
const orderToAdd = {
1084+
userId: 1,
1085+
productId: 2,
1086+
mode: 'approved',
1087+
};
1088+
1089+
//Act
1090+
const response = await axiosAPIClient.post('/order', orderToAdd);
1091+
1092+
//Assert
1093+
expect(response.status).toBe(200);
1094+
});
1095+
```
1096+
1097+
</details>
1098+
1099+
<br/>
1100+
1101+
1102+
## ⚪ ️2.13 Test the five potential outcomes
10571103

10581104
:white_check_mark: **Do:** When planning your tests, consider covering the five typical flow's outputs. When your test is triggering some action (e.g., API call), a reaction is happening, something meaningful occurs and calls for testing. Note that we don't care about how things work. Our focus is on outcomes, things that are noticeable from the outside and might affect the user. These outcomes/reactions can be put in 5 categories:
10591105

0 commit comments

Comments
 (0)