Skip to content

Commit c75e3f5

Browse files
authored
Merge pull request #198 from behrends/Automated_testing_with_Mocha
Automated testing with Mocha
2 parents fdb99a6 + 914e3bf commit c75e3f5

File tree

12 files changed

+205
-205
lines changed

12 files changed

+205
-205
lines changed

1-js/03-code-quality/05-testing-mocha/3-pow-test-wrong/solution.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
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.
22

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.
44

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.
66

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*.
88

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.
1010

11-
Like this:
11+
So zum Beispiel:
1212
```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() {
1515
assert.equal(pow(5, 1), 5);
1616
});
1717

18-
it("5 in the power of 2 equals 25", function() {
18+
it("5 in der Potenz 2 gleich 25", function() {
1919
assert.equal(pow(5, 2), 25);
2020
});
2121

22-
it("5 in the power of 3 equals 125", function() {
22+
it("5 in der Potenz 3 gleich 125", function() {
2323
assert.equal(pow(5, 3), 125);
2424
});
2525
});
2626
```
2727

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.
2929

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:
3131

3232

3333
```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() {
3636
assert.equal(pow(5, 1), 5);
3737
});
3838

3939
*!*
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() {
4242
assert.equal(pow(5, 2), 25);
4343
});
4444
*/!*
4545

46-
it("5 in the power of 3 equals 125", function() {
46+
it("5 in der Potenz 3 gleich 125", function() {
4747
assert.equal(pow(5, 3), 125);
4848
});
4949
});

1-js/03-code-quality/05-testing-mocha/3-pow-test-wrong/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ importance: 5
22

33
---
44

5-
# What's wrong in the test?
5+
# Was ist falsch mit dem Test?
66

7-
What's wrong in the test of `pow` below?
7+
Was ist falsch bei dem Test von `pow` unten?
88

99
```js
10-
it("Raises x to the power n", function() {
10+
it("Erhebt x zur Potenz n", function() {
1111
let x = 5;
1212

1313
let result = x;
@@ -21,4 +21,4 @@ it("Raises x to the power n", function() {
2121
});
2222
```
2323

24-
P.S. Syntactically the test is correct and passes.
24+
P.S. Syntaxmäßig ist der Test korrekt und besteht.

1-js/03-code-quality/05-testing-mocha/article.md

Lines changed: 156 additions & 156 deletions
Large diffs are not rendered by default.

1-js/03-code-quality/05-testing-mocha/beforeafter.view/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ describe("test", function() {
66

77
// This is because of the "alert" function, because if you delay pressing the "OK" button the tests will not pass!
88

9-
before(() => alert("Testing startedbefore all tests"));
10-
after(() => alert("Testing finishedafter all tests"));
9+
before(() => alert("Test beginntvor allen Tests"));
10+
after(() => alert("Test abgeschlossennach allen Tests"));
1111

12-
beforeEach(() => alert("Before a testenter a test"));
13-
afterEach(() => alert("After a testexit a test"));
12+
beforeEach(() => alert("Vor einem Testbeginne einen Test"));
13+
afterEach(() => alert("Nach einem Testbeende einen Test"));
1414

1515
it('test 1', () => alert(1));
1616
it('test 2', () => alert(2));

1-js/03-code-quality/05-testing-mocha/index.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!-- add mocha css, to show results -->
4+
<!-- Füge das Mocha CSS hinzu, um die Ergebnisse anzuzeigen -->
55
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.css">
6-
<!-- add mocha framework code -->
6+
<!-- Füge den Mocha Framework-Code hinzu -->
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
88
<script>
9-
mocha.setup('bdd'); // minimal setup
9+
mocha.setup('bdd'); // minimales Setup
1010
</script>
11-
<!-- add chai -->
11+
<!-- Füge Chai hinzu -->
1212
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js"></script>
1313
<script>
14-
// chai has a lot of stuff, let's make assert global
14+
// Chai hat viele Funktionen, lass uns assert global machen
1515
let assert = chai.assert;
1616
</script>
1717
</head>
@@ -20,17 +20,17 @@
2020

2121
<script>
2222
function pow(x, n) {
23-
/* function code is to be written, empty now */
23+
/* Funktionscode muss geschrieben werden, ist momentan leer */
2424
}
2525
</script>
2626

27-
<!-- the script with tests (describe, it...) -->
27+
<!-- das Skript mit Tests (describe, it...) -->
2828
<script src="test.js"></script>
2929

30-
<!-- the element with id="mocha" will contain test results -->
30+
<!-- Das Element mit der ID "mocha" wird die Testergebnisse enthalten -->
3131
<div id="mocha"></div>
3232

33-
<!-- run tests! -->
33+
<!-- Führe die Tests aus! -->
3434
<script>
3535
mocha.run();
3636
</script>

1-js/03-code-quality/05-testing-mocha/pow-1.view/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe("pow", function() {
22

3-
it("raises to n-th power", function() {
3+
it("erhöht auf die n-te Potenz", function() {
44
assert.equal(pow(2, 3), 8);
55
});
66

1-js/03-code-quality/05-testing-mocha/pow-2.view/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
describe("pow", function() {
22

3-
it("2 raised to power 3 is 8", function() {
3+
it("2 erhöht auf Potenz 3 ist 8", function() {
44
assert.equal(pow(2, 3), 8);
55
});
66

7-
it("3 raised to power 4 is 81", function() {
7+
it("3 erhöht auf Potenz 4 ist 81", function() {
88
assert.equal(pow(3, 4), 81);
99
});
1010

1-js/03-code-quality/05-testing-mocha/pow-3.view/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ describe("pow", function() {
22

33
function makeTest(x) {
44
let expected = x * x * x;
5-
it(`${x} in the power 3 is ${expected}`, function() {
5+
it(`${x} zur Potenz 3 ist ${expected}`, function() {
66
assert.equal(pow(x, 3), expected);
77
});
88
}

1-js/03-code-quality/05-testing-mocha/pow-4.view/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
describe("pow", function() {
22

3-
describe("raises x to power 3", function() {
3+
describe("erhöht x auf Potenz 3", function() {
44

55
function makeTest(x) {
66
let expected = x * x * x;
7-
it(`${x} in the power 3 is ${expected}`, function() {
7+
it(`${x} zur Potenz 3 ist ${expected}`, function() {
88
assert.equal(pow(x, 3), expected);
99
});
1010
}

1-js/03-code-quality/05-testing-mocha/pow-full.view/test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
describe("pow", function() {
22

3-
describe("raises x to power 3", function() {
3+
describe("erhöht x auf Potenz 3", function() {
44

55
function makeTest(x) {
66
let expected = x * x * x;
7-
it(`${x} in the power 3 is ${expected}`, function() {
7+
it(`${x} zur Potenz 3 is ${expected}`, function() {
88
assert.equal(pow(x, 3), expected);
99
});
1010
}
@@ -15,11 +15,11 @@ describe("pow", function() {
1515

1616
});
1717

18-
it("if n is negative, the result is NaN", function() {
18+
it("für negatives n ist das Ergebnis NaN", function() {
1919
assert.isNaN(pow(2, -1));
2020
});
2121

22-
it("if n is not integer, the result is NaN", function() {
22+
it("für nicht-ganzzahliges n ist das Ergebnis NaN", function() {
2323
assert.isNaN(pow(2, 1.5));
2424
});
2525

0 commit comments

Comments
 (0)