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.

Warning: The JUM module has been dropped in Mozmill 2.0. Please make use of the assertions API instead.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:90 次

字数:5551

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文