Browse Source

doc: note that tests should include a description

Update the Writing Tests guide to specify that tests should include a
brief description of what they are designed to test.

PR-URL: https://github.com/nodejs/node/pull/9415

Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>oc
v6
Gibson Fahnestock 8 years ago
parent
commit
3e6cc607b0
  1. 53
      doc/guides/writing_tests.md

53
doc/guides/writing_tests.md

@ -23,23 +23,27 @@ Tests can be added for multiple reasons:
Let's analyze this very basic test from the Node.js test suite: Let's analyze this very basic test from the Node.js test suite:
```javascript ```javascript
1 'use strict'; 1 'use strict';
2 const common = require('../common'); 2 const common = require('../common');
3 const http = require('http'); 3
4 const assert = require('assert'); 4 // This test ensures that the http-parser can handle UTF-8 characters
5 5 // in the http header.
6 const server = http.createServer(common.mustCall((req, res) => { 6
7 res.end('ok'); 7 const http = require('http');
8 })); 8 const assert = require('assert');
9 server.listen(0, () => { 9
10 http.get({ 10 const server = http.createServer(common.mustCall((req, res) => {
11 port: server.address().port, 11 res.end('ok');
12 headers: {'Test': 'Düsseldorf'} 12 }));
13 }, common.mustCall((res) => { 13 server.listen(0, () => {
14 assert.equal(res.statusCode, 200); 14 http.get({
15 server.close(); 15 port: server.address().port,
16 })); 16 headers: {'Test': 'Düsseldorf'}
17 }); 17 }, common.mustCall((res) => {
18 assert.strictEqual(res.statusCode, 200);
19 server.close();
20 }));
21 });
``` ```
**Lines 1-2** **Lines 1-2**
@ -60,7 +64,18 @@ require('../common');
Why? It checks for leaks of globals. Why? It checks for leaks of globals.
**Lines 3-4** **Lines 4-5**
```javascript
// This test ensures that the http-parser can handle UTF-8 characters
// in the http header.
```
A test should start with a comment containing a brief description of what it is
designed to test.
**Lines 7-8**
```javascript ```javascript
const http = require('http'); const http = require('http');
@ -72,7 +87,7 @@ modules should only include core modules.
The `assert` module is used by most of the tests to check that the assumptions The `assert` module is used by most of the tests to check that the assumptions
for the test are met. for the test are met.
**Lines 6-17** **Lines 10-21**
This is the body of the test. This test is quite simple, it just tests that an This is the body of the test. This test is quite simple, it just tests that an
HTTP server accepts `non-ASCII` characters in the headers of an incoming HTTP server accepts `non-ASCII` characters in the headers of an incoming

Loading…
Cancel
Save