Skip to content

Commit 69c19a3

Browse files
authored
docs: translated section 4 (#8)
1 parent 7faa9ed commit 69c19a3

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

readme-jp.md

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,140 +1523,142 @@ describe("visual validation", () => {
15231523

15241524
<br/><br/>
15251525

1526-
# Section 4️⃣: Measuring Test Effectiveness
1526+
# Section 4️⃣: テストの効果測定
15271527

15281528
<br/><br/>
15291529

1530-
## ️ 4.1 Get enough coverage for being confident, ~80% seems to be the lucky number
1530+
## ️4.1 十分なカバレッジを確保して自信を持つ、〜80%が幸運な数字のよう
15311531

1532-
:white_check_mark: **Do:** The purpose of testing is to get enough confidence for moving fast, obviously the more code is tested the more confident the team can be. Coverage is a measure of how many code lines (and branches, statements, etc) are being reached by the tests. So how much is enough? 10–30% is obviously too low to get any sense about the build correctness, on the other side 100% is very expensive and might shift your focus from the critical paths to the exotic corners of the code. The long answer is that it depends on many factors like the type of application — if you’re building the next generation of Airbus A380 than 100% is a must, for a cartoon pictures website 50% might be too much. Although most of the testing enthusiasts claim that the right coverage threshold is contextual, most of them also mention the number 80% as a thumb of a rule ([Fowler: “in the upper 80s or 90s”](https://martinfowler.com/bliki/TestCoverage.html)) that presumably should satisfy most of the applications.
1532+
:white_check_mark: **こうしましょう:** テストの目的は速く動くための十分な自信を得ることです。もちろん、より多くのコードがテストされればチームはより自信を持てます。カバレッジは、テストによってどれだけのコード行(およびブランチ、ステートメントなど)が到達されているかを測る指標です。では、どの程度が十分でしょうか?10–30%はビルドの正確性について判断するには明らかに低すぎ、逆に100%は非常に高価で、重大な経路からコードの珍しい隅に関心が移る可能性があります。長い答えとしては、多くの要因、例えばアプリケーションの種類によります。次世代のAirbus A380を構築するなら100%は必須ですが、漫画の画像サイトでは50%でさえ多すぎるかもしれません。ほとんどのテスト愛好家は、適切なカバレッジ閾値がコンテキストに依存すると主張しますが、多くの人が80%という数値を一般的なルールとして言及しています([Fowler: "上位の80または90%"](https://martinfowler.com/bliki/TestCoverage.html))、これはおそらくほとんどのアプリケーションを満足させるでしょう。
15331533

1534-
Implementation tips: You may want to configure your continuous integration (CI) to have a coverage threshold ([Jest link](https://jestjs.io/docs/en/configuration.html#collectcoverage-boolean)) and stop a build that doesn’t stand to this standard (it’s also possible to configure threshold per component, see code example below). On top of this, consider detecting build coverage decrease (when a newly committed code has less coverage) — this will push developers raising or at least preserving the amount of tested code. All that said, coverage is only one measure, a quantitative based one, that is not enough to tell the robustness of your testing. And it can also be fooled as illustrated in the next bullets
1534+
実装のヒント: 継続的インテグレーション(CI)にカバレッジ閾値を設定し、これに準拠しないビルドを停止するように設定するかもしれません([Jestリンク](https://jestjs.io/docs/en/configuration.html#collectcoverage-boolean))。コンポーネントごとに閾値を設定することも可能です(下記のコード例を参照)。加えて、新しくコミットされたコードがカバレッジを減少している場合の検出を検討してください。これにより開発者はテストコードの量を増やすか、少なくとも維持するよう促されます。とは言え、カバレッジは一つの指標であり、定量的に基づいたもので、テストの堅牢性を伝えるには不十分です。そして、次の箇条書きで示すように、誤魔化されることもあります。
15351535

15361536
<br/>
15371537

1538-
**Otherwise:** Confidence and numbers go hand in hand, without really knowing that you tested most of the system — there will also be some fear and fear will slow you down
1538+
**さもなくば:** 自信と数字は密接な関係があり、システムのほとんどをテストしたと本当に知ることがなければ、恐怖が生まれ、その恐怖はあなたを遅くします。
15391539

15401540
<br/>
15411541

1542-
<details><summary>✏ <b>Code Examples</b></summary>
1542+
<details><summary>✏ <b>コード例</b></summary>
15431543

15441544
<br/>
15451545

1546-
### :clap: Example: A typical coverage report
1546+
### :clap: 例: 典型的なカバレッジレポート
15471547

1548-
![alt text](assets/bp-18-yoni-goldberg-code-coverage.png "A typical coverage report")
1548+
![alt text](assets/bp-18-yoni-goldberg-code-coverage.png "典型的なカバレッジレポート")
15491549

15501550
<br/>
15511551

1552-
### :clap: Doing It Right Example: Setting up coverage per component (using Jest)
1552+
### :clap: 正しい例: コンポーネントごとにカバレッジを設定する(Jestを使用)
15531553

1554-
![](https://img.shields.io/badge/🔨%20Example%20using%20Jest-blue.svg "Using Jest")
1554+
![](https://img.shields.io/badge/🔨%20Example%20using%20Jest-blue.svg "Jestを使用")
15551555

1556-
![alt text](assets/bp-18-code-coverage2.jpeg "Setting up coverage per component (using Jest)")
1556+
![alt text](assets/bp-18-code-coverage2.jpeg "コンポーネントごとにカバレッジを設定する(Jestを使用)")
15571557

15581558
</details>
15591559

15601560
<br/><br/>
15611561

1562-
## ⚪ ️ 4.2 Inspect coverage reports to detect untested areas and other oddities
1562+
## ⚪ ️4.2 カバレッジレポートを検査して未テストの領域やその他の異常を検出する
1563+
1564+
:white_check_mark: **こうしましょう:** 一部の問題は見落とされ、伝統的なツールを使って見つけるのが非常に難しいです。これらは本当にバグではなく、重大な影響を及ぼす可能性のある驚くべきアプリケーションの挙動です。例えば、あるコードエリアがまったく呼び出されないか、ほとんど呼び出されないことがあります — ‘PricingCalculator’クラスが常に製品価格を設定していると思っていたのに、実際には一度も呼び出されていない、ということがあります。DBには10000の製品があり、多くの販売があるのに… コードカバレッジレポートはアプリケーションがあなたの思う通りに動作しているかどうかを理解するのに役立ちます。それ以外にも、どの種類のコードがテストされていないかを強調表示することができます — コードの80%がテストされたという情報では、重要な部分がカバーされているかはわかりません。レポートの生成は簡単です — カバレッジ追跡を付けて本番環境またはテスト中にアプリを実行し、各コードエリアがどのくらいの頻度で呼び出されるかを強調したカラフルなレポートを確認します。これに目を通す時間を取れば、いくつかの重要な発見をするかもしれません。
15631565

1564-
:white_check_mark: **Do:** Some issues sneak just under the radar and are really hard to find using traditional tools. These are not really bugs but more of surprising application behavior that might have a severe impact. For example, often some code areas are never or rarely being invoked — you thought that the ‘PricingCalculator’ class is always setting the product price but it turns out it is actually never invoked although we have 10000 products in DB and many sales… Code coverage reports help you realize whether the application behaves the way you believe it does. Other than that, it can also highlight which types of code is not tested — being informed that 80% of the code is tested doesn’t tell whether the critical parts are covered. Generating reports is easy — just run your app in production or during testing with coverage tracking and then see colorful reports that highlight how frequent each code area is invoked. If you take your time to glimpse into this data — you might find some gotchas
15651566
<br/>
15661567

1567-
**Otherwise:** If you don’t know which parts of your code are left un-tested, you don’t know where the issues might come from
1568+
**さもなくば:** コードのどの部分がテストされていないかわからなければ、問題がどこから来る可能性があるかわかりません。
15681569

15691570
<br/>
15701571

1571-
<details><summary>✏ <b>Code Examples</b></summary>
1572+
<details><summary>✏ <b>コード例</b></summary>
15721573

15731574
<br/>
15741575

1575-
### :thumbsdown: Anti-Pattern Example: What’s wrong with this coverage report?
1576+
### :thumbsdown: アンチパターン例: このカバレッジレポートの何が問題なのでしょうか?
15761577

1577-
Based on a real-world scenario where we tracked our application usage in QA and find out interesting login patterns (Hint: the amount of login failures is non-proportional, something is clearly wrong. Finally it turned out that some frontend bug keeps hitting the backend login API)
1578+
実際の事例に基づき、QAでアプリケーションの使用を追跡し、興味深いログインパターンを発見しました(ヒント: ログイン失敗の回数が不相応で、何かが明らかにおかしい。最終的には、あるフロントエンドのバグがバックエンドのログインAPIを繰り返し叩いていたことが判明しました)
15781579

1579-
![alt text](assets/bp-19-coverage-yoni-goldberg-nodejs-consultant.png "What’s wrong with this coverage report?")
1580+
![alt text](assets/bp-19-coverage-yoni-goldberg-nodejs-consultant.png "このカバレッジレポートの何が問題なのでしょうか?")
15801581

15811582
</details>
15821583

15831584
<br/><br/>
15841585

1585-
## ️ 4.3 Measure logical coverage using mutation testing
1586+
## ️4.3 ミューテーションテストを使用して論理的カバレッジを測定する
15861587

1587-
:white_check_mark: **Do:** The Traditional Coverage metric often lies: It may show you 100% code coverage, but none of your functions, even not one, return the right response. How come? it simply measures over which lines of code the test visited, but it doesn’t check if the tests actually tested anything — asserted for the right response. Like someone who’s traveling for business and showing his passport stamps — this doesn’t prove any work done, only that he visited few airports and hotels.
1588+
:white_check_mark: **こうしましょう:** 伝統的なカバレッジ指標はしばしば誤解を招きます。100%のコードカバレッジを示していても、関数がひとつも、正しい応答を返していない可能性があります。どうしてでしょう?それはテストがどのコード行を訪れたかを測定するだけで、実際にテストが何かを検証したかどうか — 正しい応答を確認したかを確認していないからです。ビジネスで旅行してパスポートのスタンプを見せる人のように — これはどんな仕事をしたかを証明しているわけではなく、単にいくつかの空港やホテルを訪れたことを示しているに過ぎません。
15881589

1589-
Mutation-based testing is here to help by measuring the amount of code that was actually TESTED not just VISITED. [Stryker](https://stryker-mutator.io/) is a JavaScript library for mutation testing and the implementation is really neat:
1590+
ミューテーションベースのテストは、単に訪問しただけでなく、実際にテストされたコードの量を測定することによって助けになります。[Stryker](https://stryker-mutator.io/)はJavaScriptのミューテーションテスト用ライブラリで、実装は非常にスマートです:
15901591

1591-
(1) it intentionally changes the code and “plants bugs”. For example the code newOrder.price===0 becomes newOrder.price!=0. This “bugs” are called mutations
1592+
(1) コードを意図的に変更し、「バグを植え付ける」。例えば、コード `newOrder.price===0``newOrder.price!=0` に変える。この「バグ」を変異(mutations)と呼びます。
15921593

1593-
(2) it runs the tests, if all succeed then we have a problem — the tests didn’t serve their purpose of discovering bugs, the mutations are so-called survived. If the tests failed, then great, the mutations were killed.
1594+
(2) テストを実行し、すべて成功したら問題があります — テストはバグを発見するという目的を果たさなかったことを意味し、この変異は生き残ったことになります。テストが失敗したなら素晴らしい、変異は駆逐されました。
1595+
1596+
すべてまたはほとんどのミューテーションが駆逐されたことを知っていることは、伝統的なカバレッジよりもはるかに高い信頼を与え、セットアップ時間は同様です。
15941597

1595-
Knowing that all or most of the mutations were killed gives much higher confidence than traditional coverage and the setup time is similar
15961598
<br/>
15971599

1598-
**Otherwise:** You’ll be fooled to believe that 85% coverage means your test will detect bugs in 85% of your code
1600+
**さもなくば:** 85%のカバレッジが、あなたのテストがコードの85%でバグを検出することを意味すると思い込まされます。
15991601

16001602
<br/>
16011603

1602-
<details><summary>✏ <b>Code Examples</b></summary>
1604+
<details><summary>✏ <b>コード例</b></summary>
16031605

16041606
<br/>
16051607

1606-
### :thumbsdown: Anti-Pattern Example: 100% coverage, 0% testing
1608+
### :thumbsdown: アンチパターンの例: 100%のカバレッジ、0%のテスト
16071609

1608-
![](https://img.shields.io/badge/🔨%20Example%20using%20Stryker-blue.svg "Using Stryker")
1610+
![](https://img.shields.io/badge/🔨%20Example%20using%20Stryker-blue.svg "Strykerを使用")
16091611

16101612
```javascript
16111613
function addNewOrder(newOrder) {
16121614
logger.log(`Adding new order ${newOrder}`);
16131615
DB.save(newOrder);
1614-
Mailer.sendMail(newOrder.assignee, `A new order was places ${newOrder}`);
1616+
Mailer.sendMail(newOrder.assignee, `A new order was placed ${newOrder}`);
16151617

16161618
return { approved: true };
16171619
}
16181620

16191621
it("Test addNewOrder, don't use such test names", () => {
16201622
addNewOrder({ assignee: "[email protected]", price: 120 });
1621-
}); //Triggers 100% code coverage, but it doesn't check anything
1623+
}); //100%のコードカバレッジを引き起こしますが、何もチェックしていません
16221624
```
16231625

16241626
<br/>
16251627

1626-
### :clap: Doing It Right Example: Stryker reports, a tool for mutation testing, detects and counts the amount of code that is not tested (Mutations)
1628+
### :clap: 正しい例: 変異テストのためのツール、Strykerレポートは、テストされていないコードの量(変異)を検出し、カウントします
16271629

1628-
![alt text](assets/bp-20-yoni-goldberg-mutation-testing.jpeg "Stryker reports, a tool for mutation testing, detects and counts the amount of code that is not tested (Mutations)")
1630+
![alt text](assets/bp-20-yoni-goldberg-mutation-testing.jpeg "ミューテーションテストのためのツール、Strykerレポートは、テストされていないコードの量(変異)を検出し、カウントします")
16291631

16301632
</details>
16311633

16321634
<br/><br/>
16331635

1634-
## ⚪ ️4.4 Preventing test code issues with Test linters
1636+
## ⚪ ️4.4 テストリンターでテストコードの問題を防ぐ
16351637

1636-
:white_check_mark: **Do:** A set of ESLint plugins were built specifically for inspecting the tests code patterns and discover issues. For example, [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) will warn when a test is written at the global level (not a son of a describe() statement) or when tests are [skipped](https://mochajs.org/#inclusive-tests) which might lead to a false belief that all tests are passing. Similarly, [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) can, for example, warn when a test has no assertions at all (not checking anything)
1638+
:white_check_mark: **こうしましょう:** ESLintプラグインのセットは、テストコードのパターンを検査して問題を発見するために特別に構築されました。例えば、[eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha)は、テストがグローバルレベル(describe()ステートメントの子ではない)で書かれている場合や、テストが[スキップ](https://mochajs.org/#inclusive-tests)されている場合に警告を出します。これにより、すべてのテストが通っているという誤った認識が生じる可能性があります。同様に、[eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest)は、テストに全くアサーションがない場合(何もチェックしていない)に警告を出すことができます。
16371639

16381640
<br/>
16391641

1640-
**Otherwise:** Seeing 90% code coverage and 100% green tests will make your face wear a big smile only until you realize that many tests aren’t asserting for anything and many test suites were just skipped. Hopefully, you didn’t deploy anything based on this false observation
1642+
**さもなくば:** 90%のコードカバレッジと100%のグリーンテストを見ると、顔が大きな笑顔に包まれますが、多くのテストが何もアサーションしておらず、多くのテストスイートがスキップされていることに気付くまでのことです。幸運を祈ることに、あなたがこの誤った認識に基づいて何もデプロイしていなかったことを。
16411643

16421644
<br/>
1643-
<details><summary>✏ <b>Code Examples</b></summary>
1645+
<details><summary>✏ <b>コード例</b></summary>
16441646

16451647
<br/>
16461648

1647-
### :thumbsdown: Anti-Pattern Example: A test case full of errors, luckily all are caught by Linters
1649+
### :thumbsdown: アンチパターン例: エラーだらけのテストケース、幸いにもすべてリンターが検出
16481650

16491651
```javascript
16501652
describe("Too short description", () => {
1651-
const userToken = userService.getDefaultToken() // *error:no-setup-in-describe, use hooks (sparingly) instead
1652-
it("Some description", () => {});//* error: valid-test-description. Must include the word "Should" + at least 5 words
1653+
const userToken = userService.getDefaultToken() // *エラー:no-setup-in-describe、代わりにフックを(慎重に)使用してください
1654+
it("Some description", () => {});//* エラー: valid-test-description. "Should"という単語を含む + 少なくとも5語
16531655
});
16541656

1655-
it.skip("Test name", () => {// *error:no-skipped-tests, error:error:no-global-tests. Put tests only under describe or suite
1656-
expect("somevalue"); // error:no-assert
1657+
it.skip("Test name", () => {// *エラー:no-skipped-tests, エラー:error:no-global-tests. テストはdescribeまたはスイートの下にのみ配置
1658+
expect("somevalue"); // エラー:no-assert
16571659
});
16581660

1659-
it("Test name", () => {*//error:no-identical-title. Assign unique titles to tests
1661+
it("Test name", () => {*//エラー:no-identical-title. テストにユニークなタイトルを割り当ててください
16601662
});
16611663
```
16621664

0 commit comments

Comments
 (0)