Mozmill Unit Test Framework

  • Revision slug: Mozmill/Mozmill_Unit_Test_Framework
  • Revision title: Mozmill Unit Test Framework
  • Revision id: 233019
  • Created:
  • Creator: Ctalbert
  • Is current revision? No
  • Comment 6 words removed

Revision Content

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 (i.e. They will not break from the function like the asserts of the Controller API).

Without further adieu, I give you the 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


Revision Source

<p>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:</p>
<p><span style="font-family: courier new,courier;"><span style="font-size: x-small;"><br>
</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;"><strong>var jumlib = {}; </strong></span></span></p>
<p><span style="font-size: small;"><strong><span style="font-family: courier new,courier;">Components.utils.import("<a class=" external" href="resource://mozmill/modules/jum.js" rel="freelink">resource://mozmill/modules/jum.js</a>", jumlib);</span></strong></span></p>
<p> </p>
<p>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 (i.e. They will not break from the function like the asserts of the Controller API).</p>
<p>Without further adieu, I give you the methods...</p>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assert(boolean, comment)</span></strong></p>
<ul> <li>This method will throw a pass or fail based on <strong>boolean</strong> and use <strong>comment</strong> as the message</li> <li><strong>boolean</strong>: can be either true or false</li> <li><strong>comment</strong>: the message to be displayed when the assertion is thrown</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertTrue(boolean, comment)</span></strong></p>
<ul> <li>This method will throw pass or fail based on <strong>boolean</strong> and use <strong>comment</strong> as the message</li> <li>If <strong>boolean</strong> is true, the assertion will pass</li> <li>If <strong>boolean </strong>is false, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertFalse(boolean, comment)</span></strong></p>
<ul> <li>This method will throw pass or fail based on <strong>boolean</strong> and use <strong>comment</strong> as the message</li> <li>If <strong>boolean</strong> is true, the assertion will fail</li> <li>If <strong>boolean</strong> is false, the assertion will pass</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertEquals(value1, value2, comment)</span></strong></p>
<ul> <li>This method compares the two values and throws pass or fail based on their equality and use <strong>comment </strong>as the message</li> <li>If <strong>value1 </strong>and <strong>value2</strong> are equal, the assertion will pass</li> <li>If <strong>value1 </strong>and <strong>value2</strong> are inequal, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertNotEquals(value1, value2, comment)</span></strong></p>
<ul> <li>This method compares the two values and throws a pass or fail based on their equality and uses <strong>comment</strong> as the message</li> <li>If <strong>value1</strong> and <strong>value2</strong> are inequal, the assertion will pass</li> <li>If <strong>value1</strong> and <strong>value2 </strong>are equal, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertNull(value, comment)</span></strong></p>
<ul> <li>This method checks whether <strong>value</strong> is null and uses <strong>comment</strong> as the message</li> <li>If <strong>value</strong> is null, the assertion will pass</li> <li>If <strong>value</strong> is not null, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertNotNull(value, comment)</span></strong></p>
<ul> <li>This method checks whether <strong>value</strong> is not null and uses <strong>comment</strong> as the message</li> <li>If <strong>value</strong> is not null, the assertion will pass</li> <li>If <strong>value</strong> is null, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertUndefined(value, comment)</span></strong></p>
<ul> <li>This method checks whether <strong>value</strong> is undefined and uses <strong>comment </strong>as the message</li> <li>If <strong>value</strong> is undefined, the assertion will pass</li> <li>If <strong>value</strong> is defined, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertNotUndefined(value, comment)</span></strong></p>
<ul> <li>This method checks whether <strong>value</strong> is defined and uses comment as the message</li> <li>If <strong>value</strong> is defined, the assertion will pass</li> <li>If <strong>value</strong> is undefined, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertNaN(value, comment)</span></strong></p>
<ul> <li>This method checks whether <strong>value</strong> is not a number and uses <strong>comment</strong> as the message</li> <li>If <strong>value</strong> is not a number, the assertion will pass</li> <li>If <strong>value</strong> is a number, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.assertNotNaN(value, comment)</span></strong></p>
<ul> <li>This method checks whether <strong>value</strong> is a number and uses <strong>comment</strong> as the message</li> <li>If <strong>value</strong> is a number, the assertion will pass</li> <li>If <strong>value</strong> is not a number, the assertion will fail</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.fail()</span></strong></p>
<ul> <li>This method throws a fail assertion and returns false</li>
</ul>
<p> </p>
<p><strong><span style="font-family: courier new,courier;">jumlib.pass()</span></strong></p>
<ul> <li>This method throws a pass assertion and returns true</li>
</ul>
<p><span style="font-family: courier new,courier;"><br>
</span></p>
Revert to this revision