|
1 | | -The test demonstrates one of the temptations a developer meets when writing tests. |
| 1 | +Der Test zeigt eine der Versuchungen, denen ein Entwickler beim Schreiben von Tests begegnet. |
2 | 2 |
|
3 | | -What we have here is actually 3 tests, but layed out as a single function with 3 asserts. |
| 3 | +Was wir hier tatsächlich haben, sind eigentlich 3 Tests, aber angeordnet als einzelne Funktion mit 3 Assertions. |
4 | 4 |
|
5 | | -Sometimes it's easier to write this way, but if an error occurs, it's much less obvious what went wrong. |
| 5 | +Manchmal ist es einfacher, auf diese Weise zu schreiben, aber wenn ein Fehler auftritt, ist es viel weniger offensichtlich, was schiefgelaufen ist. |
6 | 6 |
|
7 | | -If an error happens in the middle of a complex execution flow, then we'll have to figure out the data at that point. We'll actually have to *debug the test*. |
| 7 | +Tritt ein Fehler in der Mitte eines komplexen Programmablaufs auf, dann müssen wir die Daten an diesem Punkt herausfinden. Wir müssen tatsächlich *den Test debuggen*. |
8 | 8 |
|
9 | | -It would be much better to break the test into multiple `it` blocks with clearly written inputs and outputs. |
| 9 | +Es wäre viel besser, den Test in mehrere `it` Blöcke aufzubrechen, mit klar geschriebenen Eingaben und Ausgaben. |
10 | 10 |
|
11 | | -Like this: |
| 11 | +So zum Beispiel: |
12 | 12 | ```js |
13 | | -describe("Raises x to power n", function() { |
14 | | - it("5 in the power of 1 equals 5", function() { |
| 13 | +describe("Erhöht x zur Potenz n", function() { |
| 14 | + it("5 in der Potenz 1 gleich 5", function() { |
15 | 15 | assert.equal(pow(5, 1), 5); |
16 | 16 | }); |
17 | 17 |
|
18 | | - it("5 in the power of 2 equals 25", function() { |
| 18 | + it("5 in der Potenz 2 gleich 25", function() { |
19 | 19 | assert.equal(pow(5, 2), 25); |
20 | 20 | }); |
21 | 21 |
|
22 | | - it("5 in the power of 3 equals 125", function() { |
| 22 | + it("5 in der Potenz 3 gleich 125", function() { |
23 | 23 | assert.equal(pow(5, 3), 125); |
24 | 24 | }); |
25 | 25 | }); |
26 | 26 | ``` |
27 | 27 |
|
28 | | -We replaced the single `it` with `describe` and a group of `it` blocks. Now if something fails we would see clearly what the data was. |
| 28 | +Wir haben das einzelnen `it` durch `describe` und eine Gruppe von `it` Blöcken ersetzt. Wenn jetzt etwas fehlschlägt, würden wir klar sehen, welche Daten es waren. |
29 | 29 |
|
30 | | -Also we can isolate a single test and run it in standalone mode by writing `it.only` instead of `it`: |
| 30 | +Außerdem können wir einen einzelnen Test isolieren und ihn im Standalone-Modus ausführen, indem wir `it.only` statt `it` schreiben: |
31 | 31 |
|
32 | 32 |
|
33 | 33 | ```js |
34 | | -describe("Raises x to power n", function() { |
35 | | - it("5 in the power of 1 equals 5", function() { |
| 34 | +describe("Erhöht x zur Potenz n", function() { |
| 35 | + it("5 in der Potenz 1 gleich 5", function() { |
36 | 36 | assert.equal(pow(5, 1), 5); |
37 | 37 | }); |
38 | 38 |
|
39 | 39 | *!* |
40 | | - // Mocha will run only this block |
41 | | - it.only("5 in the power of 2 equals 25", function() { |
| 40 | + // Mocha wird nur diesen Block ausführen |
| 41 | + it.only("5 in der Potenz 2 gleich 25", function() { |
42 | 42 | assert.equal(pow(5, 2), 25); |
43 | 43 | }); |
44 | 44 | */!* |
45 | 45 |
|
46 | | - it("5 in the power of 3 equals 125", function() { |
| 46 | + it("5 in der Potenz 3 gleich 125", function() { |
47 | 47 | assert.equal(pow(5, 3), 125); |
48 | 48 | }); |
49 | 49 | }); |
|
0 commit comments