Skip to content

Commit 217e0b7

Browse files
committed
Remove Section 2.7 (duplicate with Section 1.9)
1 parent 146725b commit 217e0b7

File tree

1 file changed

+0
-55
lines changed

1 file changed

+0
-55
lines changed

readme-zh-TW.md

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -919,61 +919,6 @@ Credit: <a href="https://github.com/TheHollidayInn" data-href="https://github.co
919919

920920
</details>
921921

922-
<br/>
923-
924-
## ⚪ ️2.7 Avoid global test fixtures and seeds, add data per-test
925-
926-
:white_check_mark: **Do:** Going by the golden rule (bullet 0), each test should add and act on its own set of DB rows to prevent coupling and easily reason about the test flow. In reality, this is often violated by testers who seed the DB with data before running the tests (also known as ‘test fixture’) for the sake of performance improvement. While performance is indeed a valid concern — it can be mitigated (see “Component testing” bullet), however, test complexity is a much painful sorrow that should govern other considerations most of the time. Practically, make each test case explicitly add the DB records it needs and act only on those records. If performance becomes a critical concern — a balanced compromise might come in the form of seeding the only suite of tests that are not mutating data (e.g. queries)
927-
<br/>
928-
929-
**Otherwise:** Few tests fail, a deployment is aborted, our team is going to spend precious time now, do we have a bug? let’s investigate, oh no — it seems that two tests were mutating the same seed data
930-
931-
<br/>
932-
933-
<details><summary>✏ <b>Code Examples</b></summary>
934-
935-
<br/>
936-
937-
### :thumbsdown: Anti-Pattern Example: tests are not independent and rely on some global hook to feed global DB data
938-
939-
![](https://img.shields.io/badge/🔧%20Example%20using%20Mocha-blue.svg "Examples with Mocha")
940-
941-
```javascript
942-
before(async () => {
943-
//adding sites and admins data to our DB. Where is the data? outside. At some external json or migration framework
944-
await DB.AddSeedDataFromJson('seed.json');
945-
});
946-
it("When updating site name, get successful confirmation", async () => {
947-
//I know that site name "portal" exists - I saw it in the seed files
948-
const siteToUpdate = await SiteService.getSiteByName("Portal");
949-
const updateNameResult = await SiteService.changeName(siteToUpdate, "newName");
950-
expect(updateNameResult).to.be(true);
951-
});
952-
it("When querying by site name, get the right site", async () => {
953-
//I know that site name "portal" exists - I saw it in the seed files
954-
const siteToCheck = await SiteService.getSiteByName("Portal");
955-
expect(siteToCheck.name).to.be.equal("Portal"); //Failure! The previous test change the name :[
956-
});
957-
958-
```
959-
960-
<br/>
961-
962-
### :clap: Doing It Right Example: We can stay within the test, each test acts on its own set of data
963-
964-
```javascript
965-
it("When updating site name, get successful confirmation", async () => {
966-
//test is adding a fresh new records and acting on the records only
967-
const siteUnderTest = await SiteService.addSite({
968-
name: "siteForUpdateTest"
969-
});
970-
const updateNameResult = await SiteService.changeName(siteUnderTest, "newName");
971-
expect(updateNameResult).to.be(true);
972-
});
973-
```
974-
975-
</details>
976-
977922
<br/><br/>
978923

979924
# Section 3️⃣: Frontend Testing

0 commit comments

Comments
 (0)