Mozmill Unit Test Framework 编辑
Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
The JUM API is basically a group of assertion methods to allow you to throw customized errors during testing. It is intended to be used for unit testing in JavaScript. To use the JUM API, you need to include jum.js
in each test file. You can do this similarly to how you include the Mozmill API:
var jumlib = {}; Components.utils.import("resource://mozmill/modules/jum.js", jumlib);
With this in place, you can simply call any of the methods we will talk about here using jumlib.method()
; It should be noted that using these asserts will "silently" fail; that is, they will not break from the function like the asserts of the Controller API.
Methods
jumlib.assert(boolean, comment)
- This method will throw a pass or fail based on boolean and use comment as the message
- boolean: can be either true or false
- comment: the message to be displayed when the assertion is thrown
jumlib.assertTrue(boolean, comment)
- This method will throw pass or fail based on boolean and use comment as the message
- If boolean is true, the assertion will pass
- If boolean is false, the assertion will fail
jumlib.assertFalse(boolean, comment)
- This method will throw pass or fail based on boolean and use comment as the message
- If boolean is true, the assertion will fail
- If boolean is false, the assertion will pass
jumlib.assertEquals(value1, value2, comment)
- This method compares the two values and throws pass or fail based on their equality and use comment as the message
- If value1 and value2 are equal, the assertion will pass
- If value1 and value2 are inequal, the assertion will fail
jumlib.assertNotEquals(value1, value2, comment)
- This method compares the two values and throws a pass or fail based on their equality and uses comment as the message
- If value1 and value2 are inequal, the assertion will pass
- If value1 and value2 are equal, the assertion will fail
jumlib.assertNull(value, comment)
- This method checks whether value is null and uses comment as the message
- If value is null, the assertion will pass
- If value is not null, the assertion will fail
jumlib.assertNotNull(value, comment)
- This method checks whether value is not null and uses comment as the message
- If value is not null, the assertion will pass
- If value is null, the assertion will fail
jumlib.assertUndefined(value, comment)
- This method checks whether value is undefined and uses comment as the message
- If value is undefined, the assertion will pass
- If value is defined, the assertion will fail
jumlib.assertNotUndefined(value, comment)
- This method checks whether value is defined and uses comment as the message
- If value is defined, the assertion will pass
- If value is undefined, the assertion will fail
jumlib.assertNaN(value, comment)
- This method checks whether value is not a number and uses comment as the message
- If value is not a number, the assertion will pass
- If value is a number, the assertion will fail
jumlib.assertNotNaN(value, comment)
- This method checks whether value is a number and uses comment as the message
- If value is a number, the assertion will pass
- If value is not a number, the assertion will fail
jumlib.fail()
- This method throws a fail assertion and returns
false
.
jumlib.pass()
- This method throws a pass assertion and returns
true
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论