My Node. js learning path (4) -- unit test and node. js unit test

Source: Internet
Author: User

My Node. js learning path (4) -- unit test and node. js unit test

NPM installation:

Npm install nodeunit-g

Supports command line and browser running. Various assertions. In node. js, modularize the method to export exports. If it is an object to export module. exports, the module is the basis of the unit test. See the following node. js code:

var fs = require('fs'),global=require('./global.js');var utils = {startWith: function(s1, s) {if (s == null || s == "" || this.length == 0 || s.length > this.length)return false;if (s1.substr(0, s.length) == s)return true;elsereturn false;return true;},/* Generate GUID */getGuid: function() {var guid = "";for (var i = 1; i <= 32; i++) {var n = Math.floor(Math.random() * 16.0).toString(16);guid += n;}return guid;},/* add log information */writeLog: function(log) {if(!log) return;var text = fs.readFileSync(global.logFile, "utf-8"),_newLog = text ? (text + "\r\n" + log) : log;fs.writeFile(global.logFile, _newLog, function(err){if(err) throw err;});}};exports.utils=utils;

./Global. js is a local global variable file. Now we use NodeUnit to test the node. js code for the above Code:

var utils=new require('./utils.js');this.TestForUtils = {'TestgetGuid': function (test) {var guid=utils.utils.getGuid();test.ok(!!guid, 'getGuid should not be null.');test.done();},'TestWritelog': function (test) {var flag=false;utils.utils.writeLog("test message");flag=true;test.ok(flag,'writeLog');test.done();},'TestStartWithWords': function (test) {var name="ad_123";test.ok(utils.utils.startWith(name, "ad_"),"startwith method should be ok");test.done();}};

Test. OK is also a general asserted. You can also use node-inspector to debug the unit test program of NodeUnit.


How to Learn nodejs

First, you must understand the basic syntax, that is, javascript;
It would be better if there is a web Programming Development Foundation.

Read more information on the official website, and there are also good entry-level online tutorials abroad, such as nodebeginner.org

After a general understanding of the overall structure, you can access some common modules, such as express.
 
Four arithmetic unit test volume learning weekly

Unit 1 (4)
Class
I. Oral calculation questions (12 points in total)
105 bytes 5 × 2 + 3 = (105 bytes 5) × 2 + 3 = 52 + 25 bytes 52 + 25 =
105 bytes 5 × (2 + 3) = 105 bytes (5 × 2 + 3) = 100 + 100 × 0 =
50 + 90 percentile (2x3) = (50 + 90) limit 2x3 = 50 + 90 percentile 2x3 =
(50 + 90 limit 2) × 3 = 72 limit 9 × 48 limit 8 = 64 limit 64 × 7 =

2. Fill in the blanks (5 + 8 = 13 points)
1. The following is a Statistical Chart of the scores of Xiaohong subjects. answer the following questions based on the statistical chart.
(1). Chinese (), Mathematics (), and foreign language.
(2). Mathematics is higher than foreign languages.
(3). mean score of the three subjects.

2. Rewrite the following steps into a comprehensive formula.
(1) 960 bytes 15 = 64 64 bytes 28 = 36 comprehensive formula _____________________________.
(2) 75 × 24 = 1800 9000 ÷ 1800 = 7200 overall formula ____________________________
(3) 810-19 = 791 791 × 2 = 1582 1582 + 216 = 1798 comprehensive formula ___________________
(4) 96 × 5 = 480 480 + 20 = 500 500 ÷ 4 = 125 overall formula ____________________

3. Judgment (correct brackets include "√", incorrect brackets include "×", and correct) (9 points)
1.720 percentile (15-3 × 2) 2.3889-(108-931) × 5 3. (800 + 200 percentile 50) × 3
= 720 percentile (12 × 2) = 3889-149 × 5 = (100 percentile 50) × 3
= 720 usd24 = 3889-745 = 20 × 3
= 30 = 3144 = 60 ()()()
4. Calculation questions (a total of 18 points for each question)
19 × 96 Jun 962 Jun 74 10000 Jun (59 + 66) × 64 5940 Jun 45 × (798 Jun 616)
(315 × 40 × 364) Listen 7 12520 × 8 × (121 × 11) (2010 × 906) × (65 + 15)

5. Text questions (6 points for each question and 18 points for each question)
1. 25 what is the sum of the products 17 and 13 added to the vendors except 175?

2. What is the difference between 13 and 12 from the quotient of 4000 divided by 25?

3. What is the difference between 6000 divided by 59 and 35?

6. Application Questions (1st sub-questions: 5 points, 30 points in total)
1. a fertilizer plant produced January tons of fertilizer in 310 and 40 tons of fertilizer in February ...... the remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.