際際滷

際際滷Share a Scribd company logo
Assertion Testing
覦蠏豌
2014. 07. 12.
1
2
http://cheezburger.com/4126178560
3
Table of Contents
 Assert
 assert.fail(actual, expected, message, operator)
 assert(value, message), assert.ok(value, [message])
 assert.equal(actual, expected, [message])
 assert.notEqual(actual, expected, [message])
 assert.deepEqual(actual, expected, [message])
 assert.notDeepEqual(actual, expected, [message])
 assert.strictEqual(actual, expected, [message])
 assert.notStrictEqual(actual, expected, [message])
 assert.throws(block, [error], [message])
 assert.doesNotThrow(block, [message])
 assert.ifError(value)
4
Assert
 誤,  襷も 朱 詞朱 襦蠏碁  譴 轟 
assert 覓語 襷 蟆曙 譯殊伎 譟郁唄 襷譟燕讌 朱  覦
  ろ碁ゼ  覈
 https://github.com/joyent/node/blob/master/lib/assert.js
 var assert = require(assert);
5
assert.fail
assert.fail(actual, expected, message, operator)
 覓伎^蟇 ろ - 譯殊伎 ろ朱危一  蟲覿襦 れ 蠍磯螳 豢ロ 
碁ゼ 覦
 覃讌 豢  ろ朱危 豢レ  / 覃讌   ろ朱危郁 豢ル
6
CODE
assert.fail
7
assert.fail(actual, expected, message, operator)
 覓伎^蟇 ろ - 譯殊伎 ろ朱危一  蟲覿襦 れ 蠍磯螳 豢ロ 
碁ゼ 覦
 覃讌 豢  ろ朱危 豢レ  / 覃讌   ろ朱危郁 豢ル
EXAMPLES
assert
assert.ok
assert(value, message) / assert.ok(value, [message])
Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);
 螳(value) 谿 語襯 
 蟇一  assert.fail ろ
 assert.equal(true, !!value, message);  
8
CODE
assert.equal
assert.notEqual
assert.equal(actual, expected, [message])
 Tests shallow, coercive equality with the equal comparison operator ( == ).
 == () 一一 蟷 , 螳 () 


assert.notEqual(actual, expected, [message])
 Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
 != 螳讌  一一 蟷 , 螳 觜(觜) 

9
CODE
CODE
assert.deepEqual
assert.notDeepEqual
assert.deepEqual(actual, expected, [message]) / assert.notDeepEqual(actual, expected, [message])
 _deepEqual 襯 伎 actual 螻 expected 襷り覲襯 觜蟲

觜蟲 譟郁唄
覈 狩 螳 燕 蟆曙, 殊一一(===) 襦 蟆一
∬鍵(expected) 螳 Date 螳豌伎 蟆曙, getTime()  伎 螳 螳 企 蟆曙 煙朱 伎
∬鍵螳 蠏 蟆曙, れ 螳 RegExp 螳豌願 螳 れ 襦狩磯ゼ 螳讌 蟆曙(`global`, `multiline`, `lastIndex`,
`ignoreCase`) 煙朱 伎
 螳螳 覈 る瑚  蟆曙, == 襦 煙 蟆一
覦一 螳豌企ゼ  覈 るジ  伎 煙
∬  襦狩(hasOwnProperty.call朱 )
∬ れ 誤(螳 螳讌 朱)
企麹 覈 れ  螳 螳 螳讌螻
狩 襦 襦狩
10
assert.strictEqual
assert.notStrictEqual
 assert.strictEqual(actual, expected, [message])
 蟆 , 讀 殊 === 襯 


 assert.notStrictEqual(actual, expected, [message])
 蟆 觜, 讀 覿殊 !==襯 
11
CODE
CODE
assert.throws
 assert.throws(block, [error],
[message])
 throw 蟆讀
  譬襯 煙, 蠏 
蟆讀  螳
12
煙襯 伎 instanceof  蟆讀
蠏  伎 覃讌 蟆讀
貉れろ  蟆讀
CODE
EXAMPLES
assert.doesNotThrow
 assert.doesNotThrow(block, [message])
 襯 覦 れ 蟆 
13
CODE
assert.ifError
 assert.ifError(value)
 螳 蟇一 語襯 , 谿語 蟆曙 throw 
 貊覦煙 error 螳 豌 覯讌 襷り覲襯   

 覓語
 覈 企 るジ れ 覈 throw new assert.AssertionError 碁,   throw err 襯

  覈  覈語 覓 - nodeDev 蟲蠍 蠏碁9れ 殊  
 https://groups.google.com/forum/#!topic/nodejs-dev/LkNlaweiZYY
14
CODE
Reference
 https://github.com/joyent/node/blob/master/lib/assert.js
 assert.ifError thread in Nodejsdev google groups
 https://groups.google.com/forum/#!topic/nodejs/
Z027Ox3M33o
 https://groups.google.com/forum/#!topic/nodejs-dev/
LkNlaweiZYY
 Node unit test
 https://github.com/caolan/nodeunit
15

More Related Content

Node.js assertion testing module

  • 2. 2
  • 4. Table of Contents Assert assert.fail(actual, expected, message, operator) assert(value, message), assert.ok(value, [message]) assert.equal(actual, expected, [message]) assert.notEqual(actual, expected, [message]) assert.deepEqual(actual, expected, [message]) assert.notDeepEqual(actual, expected, [message]) assert.strictEqual(actual, expected, [message]) assert.notStrictEqual(actual, expected, [message]) assert.throws(block, [error], [message]) assert.doesNotThrow(block, [message]) assert.ifError(value) 4
  • 5. Assert 誤, 襷も 朱 詞朱 襦蠏碁 譴 轟 assert 覓語 襷 蟆曙 譯殊伎 譟郁唄 襷譟燕讌 朱 覦 ろ碁ゼ 覈 https://github.com/joyent/node/blob/master/lib/assert.js var assert = require(assert); 5
  • 6. assert.fail assert.fail(actual, expected, message, operator) 覓伎^蟇 ろ - 譯殊伎 ろ朱危一 蟲覿襦 れ 蠍磯螳 豢ロ 碁ゼ 覦 覃讌 豢 ろ朱危 豢レ / 覃讌 ろ朱危郁 豢ル 6 CODE
  • 7. assert.fail 7 assert.fail(actual, expected, message, operator) 覓伎^蟇 ろ - 譯殊伎 ろ朱危一 蟲覿襦 れ 蠍磯螳 豢ロ 碁ゼ 覦 覃讌 豢 ろ朱危 豢レ / 覃讌 ろ朱危郁 豢ル EXAMPLES
  • 8. assert assert.ok assert(value, message) / assert.ok(value, [message]) Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message); 螳(value) 谿 語襯 蟇一 assert.fail ろ assert.equal(true, !!value, message); 8 CODE
  • 9. assert.equal assert.notEqual assert.equal(actual, expected, [message]) Tests shallow, coercive equality with the equal comparison operator ( == ). == () 一一 蟷 , 螳 () assert.notEqual(actual, expected, [message]) Tests shallow, coercive non-equality with the not equal comparison operator ( != ). != 螳讌 一一 蟷 , 螳 觜(觜) 9 CODE CODE
  • 10. assert.deepEqual assert.notDeepEqual assert.deepEqual(actual, expected, [message]) / assert.notDeepEqual(actual, expected, [message]) _deepEqual 襯 伎 actual 螻 expected 襷り覲襯 觜蟲 觜蟲 譟郁唄 覈 狩 螳 燕 蟆曙, 殊一一(===) 襦 蟆一 ∬鍵(expected) 螳 Date 螳豌伎 蟆曙, getTime() 伎 螳 螳 企 蟆曙 煙朱 伎 ∬鍵螳 蠏 蟆曙, れ 螳 RegExp 螳豌願 螳 れ 襦狩磯ゼ 螳讌 蟆曙(`global`, `multiline`, `lastIndex`, `ignoreCase`) 煙朱 伎 螳螳 覈 る瑚 蟆曙, == 襦 煙 蟆一 覦一 螳豌企ゼ 覈 るジ 伎 煙 ∬ 襦狩(hasOwnProperty.call朱 ) ∬ れ 誤(螳 螳讌 朱) 企麹 覈 れ 螳 螳 螳讌螻 狩 襦 襦狩 10
  • 11. assert.strictEqual assert.notStrictEqual assert.strictEqual(actual, expected, [message]) 蟆 , 讀 殊 === 襯 assert.notStrictEqual(actual, expected, [message]) 蟆 觜, 讀 覿殊 !==襯 11 CODE CODE
  • 12. assert.throws assert.throws(block, [error], [message]) throw 蟆讀 譬襯 煙, 蠏 蟆讀 螳 12 煙襯 伎 instanceof 蟆讀 蠏 伎 覃讌 蟆讀 貉れろ 蟆讀 CODE EXAMPLES
  • 14. assert.ifError assert.ifError(value) 螳 蟇一 語襯 , 谿語 蟆曙 throw 貊覦煙 error 螳 豌 覯讌 襷り覲襯 覓語 覈 企 るジ れ 覈 throw new assert.AssertionError 碁, throw err 襯 覈 覈語 覓 - nodeDev 蟲蠍 蠏碁9れ 殊 https://groups.google.com/forum/#!topic/nodejs-dev/LkNlaweiZYY 14 CODE
  • 15. Reference https://github.com/joyent/node/blob/master/lib/assert.js assert.ifError thread in Nodejsdev google groups https://groups.google.com/forum/#!topic/nodejs/ Z027Ox3M33o https://groups.google.com/forum/#!topic/nodejs-dev/ LkNlaweiZYY Node unit test https://github.com/caolan/nodeunit 15