Confirmed users
35
edits
Line 111: | Line 111: | ||
Moztest is a package that allows you to store and process test results. | Moztest is a package that allows you to store and process test results. | ||
You can use the classes in the | You can use the classes in the <tt>results</tt> submodule to store results and then the classes in the <tt>output</tt> subpackage to get useful representations of them (for example xUnit, Autolog). | ||
You can store environment data (i.e. OS that was used) using the | You can store environment data (i.e. OS that was used) using the <tt>TestContext</tt> class. | ||
Moztest supports two ways of storing test results: either creating them live, while running the tests, or creating them after the tests have been run. | Moztest supports two ways of storing test results: either creating them live, while running the tests, or creating them after the tests have been run. | ||
Line 119: | Line 119: | ||
==== Creating the results objects while running the tests ==== | ==== Creating the results objects while running the tests ==== | ||
1. Instantiate a | 1. Instantiate a <tt>TestResult</tt> object: | ||
<pre> | <pre> | ||
t = TestResult('example', test_class='doc', context=TestContext(product='Kuma'), result_expected='PASS') | t = TestResult('example', test_class='doc', context=TestContext(product='Kuma'), result_expected='PASS') | ||
</pre> | </pre> | ||
The test's | The test's <tt>time_start</tt> property will be set the current time. | ||
2. Finalize the object (assuming the test passed): | 2. Finalize the object (assuming the test passed): | ||
Line 131: | Line 131: | ||
</pre> | </pre> | ||
The test's | The test's <tt>time_end</tt> property will be set to the current time as expected. | ||
Or, if the test failed: | Or, if the test failed: | ||
Line 139: | Line 139: | ||
</pre> | </pre> | ||
After you call | After you call <tt>finish()</tt>, the test's <tt>result</tt> property will contain the standard string for the corresponding result it has. For example, <tt>UNEXPECTED-FAIL</tt>. | ||
Also, you can use the | Also, you can use the <tt>duration</tt> property to see how long a test took. | ||
You manage test result data by using a | You manage test result data by using a <tt>TestResultCollection</tt>. The <tt>output</tt> subpackage expects <tt>TestResultCollection</tt> objects as well. These behave similar to lists. In fact, they are lists. | ||
The general pattern is this: | The general pattern is this: | ||
Line 165: | Line 165: | ||
The pattern differs, depending on the type of the results. | The pattern differs, depending on the type of the results. | ||
If they are python unittest-based results (i.e. Marionette), you can use a convenience classmethod of | If they are python <tt>unittest</tt>-based results (i.e. <tt>Marionette</tt>), you can use a convenience classmethod of <tt>TestResultCollection</tt>: | ||
<pre> | <pre> | ||
Line 173: | Line 173: | ||
</pre> | </pre> | ||
If the results you have are not based on python's unittest results - for example, XPCShellTest | If the results you have are not based on python's <tt>unittest</tt> results - for example, <tt>XPCShellTest</tt> results are not, the general pattern is something like this (the way in which you get the relevant data from the test may vary): | ||
<pre> | <pre> |