|
19 | 19 |
|
20 | 20 | Read nearby tests before you choose syntax and organization. |
21 | 21 |
|
22 | | -Follow established conventions when they preserve the behavior required by this skill. |
| 22 | +A pattern that the project repeats is a convention, and a convention of the project outranks each rule in this skill. Follow it, and write the new test in the same shape. |
| 23 | + |
| 24 | +The rules in this skill govern the test that you write now. A test that exists and follows a convention is not a defect of that test. Do not delete it, and do not rewrite it. Tell the user what the convention costs, if it costs something, and let the user decide. |
23 | 25 |
|
24 | 26 | Use the project convention for each item that follows: |
25 | 27 |
|
|
39 | 41 | - Test observable behavior and application contracts. A test must pass after an implementation change if the behavior stays the same. |
40 | 42 | - Cover every changed decision and each applicable high-value failure mode. A decision is a branch, a validation, a calculation, or an authorization. |
41 | 43 | - Exercise declarations through behavior instead of repeating their text. |
42 | | -- Leave framework behavior to the framework tests. |
43 | | -- Keep each test only when it can detect a distinct defect. |
| 44 | +- Leave framework behavior to the framework tests. A test of what this project configures is not a test of the framework. A relation that adds a constraint, a cast, a scope, and a rule of the validation each belong to this project. |
| 45 | +- Keep each test that can detect a distinct defect. When two tests find the same defect, trim the test at the higher layer to one case, and report the duplicate to the user. Do not delete a test. |
44 | 46 | - Write a feature test first. Write a unit test only for logic that does not use the framework. |
45 | 47 | @if($pest && $assist->hasPackage('pestphp/pest-plugin-browser')) |
46 | 48 | - Write a browser test only for behavior in JavaScript that a feature test cannot reach. Put a browser test in `tests/Browser`, and call `assertNoJavaScriptErrors()` in it. |
|
49 | 51 | @else |
50 | 52 | - Write a feature test for each behavior that a request can reach. A test in a real browser needs {{ $pest ? '`pestphp/pest-plugin-browser`' : '`laravel/dusk`' }} and a browser download, and this project installs neither of them. Tell the user about the package only if the user asks for a test in a real browser. |
51 | 53 | @endif |
| 54 | +@if($pest) |
| 55 | +- Judge an architecture test by the convention that it protects, and not by the rules above. An `arch()` test states a rule for a complete directory, such as the parent of each model, the classes that may use an enum, or the methods that each factory declares. It is a declaration check by design, and it fails when one new file breaks the convention. |
| 56 | +@endif |
52 | 57 | - Use the test tools that the project installs. Add a new test dependency, plugin, or browser only after the user asks for it. |
53 | 58 |
|
54 | 59 | ## How to Apply |
|
0 commit comments