Test Fixture
Introduction
h-x-test-suite is a draft microformat for publishing code testing data on the web. It’s the microformats2 version of the test-fixture poshformat. Neither have been through the microformats design and community review process.
The test-suite is a description of a group software tests. These test are embedded into HTML using as POSH pattern based on microformats2. Each test-suite can contain a number of test-fixture, which are the individual test.
Example
<div class="h-x-test-suite">
<h1 class="p-name">h-card parsing tests</h1>
<p class="p-description">This page was design to test the parsing of h-card. These tests are part of the microformats 2 test suite.</p>
<section class="p-x-test-fixture h-x-test-fixture">
<h1 class="p-name">Just a name (<span class="p-format">h-card</span> parsing test)</h1>
<div class="e-x-microformat">
<p class="h-card">Frances Berriman</p>
</div>
<h3>The expected JSON output:</h3>
<pre class="prettyprint"><code class="e-x-output language-json">
{
"items": [{
"type": ["h-card"],
"properties": {
"name": ["Frances Berriman"]
}
}]
}</code></pre>
</section>
</div>
</div>
Properties
- p-name — The name of the test-suite
- p-description — An expanded description of the test-suite
- p-author — The authors of the test-suite, these are mark-up as h-cards
- p-x-history — The history of changes to test-suite, these are mark-up as h-entry
Properties of a test-fixture
- p-name — The title of the test-fixture
- p-x-format — The name of microformat to be tested
- e-x-microformat — The HTML mark-up containing the microformat to test
- p-x-output — This is an example output which would be expected form the test
- p-x-assert — The assert is the component parts of a test
Properties of a assert
- p-x-test — Describes the property to be tested
- p-x-result — Describes expected result form the test
- p-summary — This is an expanded piece of text about the test
test-fixture
This format was originally developed for the UfXtract test-suite but is now public domain. This specification should be considered a draft. Contents are subject to change. It is provided here for reference and as a basis for discussion and ongoing development.
Structure
- class="test-fixture"
- class="summary"
- class="description"
- class="format"
- class="author" (hcard)
- class="output"
- class="type" [JSON,XML]
- class="value"
- class="assert"
- class="test"
- class="result"
- class="comment"
- class="history" (vevent)
Key
- Single occurrence required
- Single occurrence optional
- Zero or More occurrences
Properties
Field details
The fields of the test-fixture schema represent the following:
test-fixture
:: The root class namesummary
:: The title of the test-fixturedescription
:: An expanded piece of text about the test-fixtureformat
:: The format to be tested ie hCardauthor
:: The authors of the test as an hCardoutput
:: The example output which would be expected form the test.type
:: The output formatvalue
:: A URL to link to the exampleassert
:: The assert is a description of a testtest
:: The element to testresult
:: The expected result for the test.comment
:: An expanded piece of text about the test.history
:: The history of changes to test-fixture, as hCalendar events
Example mark up
<div class="test-fixture"> <h1 class="summary">hCard 1 - single occurrence test</h1> <p class="description"> This page was designed to test the values of a hcard which are meant to have only a single occurrence parsed correctly. </p> <p>From: <a href="default.htm"><span class="format">hCard</span> testsuite 1.0</a></p> <p class="author vcard"> Author: <a class="url fn" href="http://www.glennjones.net/">Glenn Jones</a> <a class="org url" href="http://www.madgex.com/">Madgex</a> </p> <p>Output examples: <ul> <li class="output"><a class="url" href="hcard1.js"><span class="type">JSON</span></a></li> <li class="output"><a class="url" href="hcard1.xml"><span class="type">XML</span></a></li> </ul> </p> <p>Tests:</p> <table id="assetTable" cellpadding="0" cellspacing="0"> <thead> <tr> <th>Test</th> <th>Result</th> <th>Comment</th> </tr> </thead> <tbody> <tr class="assert"> <td class="test">vcard[0].fn</td> <td class="result">IsEqualTo("John Doe")</td> <td class="comment">The fn (formatted name) is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].n.given-name[0]</td> <td class="result">IsEqualTo("John")</td> <td class="comment">The n (name) is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].bday</td> <td class="result">IsEqualTo("2000-01-01T00:00:00-0800")</td> <td class="comment">The bday (birthday) is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].class</td> <td class="result">IsEqualTo("Public")</td> <td class="comment">The class is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].geo.latitude</td> <td class="result">IsEqualTo("30.267991")</td> <td class="comment">The geo is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].rev</td> <td class="result">IsEqualTo("2008-01-01T13:45")</td> <td class="comment">The rev is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].role</td> <td class="result">IsEqualTo("Designer")</td> <td class="comment">The role is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].sort-string</td> <td class="result">IsEqualTo("John")</td> <td class="comment">The sort-string is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].tz</td> <td class="result">IsEqualTo("-05:00")</td> <td class="comment">The tz is a singular value</td> </tr> <tr class="assert"> <td class="test">vcard[0].uid</td> <td class="result">IsEqualTo("com.johndoe/profiles/johndoe")</td> <td class="comment">The uid is a singular value</td> </tr> </tbody> </table> <p>History:</p> <ul> <li class="history vevent"> <span class="summary">Created</span>: <abbr class="dtstart" title="2008-04-08">8 April 2008</abbr> <span class="description">by Glenn Jones</span> </li> </ul> </div>
Embeding tests
You can embed the test microformat into the same page as the test-fixture. As the test-fixture itself contains microformats such as hCards so we need to define what section of the page to we should be testing. For the sake of consistency within the microformats test-suite all microformats that are been tested should be contain in a HTML element with the id “uf”.
<div id="uf"> <div class="vcard"> <!-- This may not be the best semantic use of HTML element --> <div class="fn n"><span class="given-name sort-string">John</span> Doe</div> <div>Birthday: <abbr class="bday" title="2000-01-01T00:00:00-08:00">January 1st, 2000</abbr></div> <div>Role: <span class="role">Designer</span></div> <div>Location: <abbr class="geo" title="30.267991;-97.739568">Brighton</abbr></div> <div>Time zone: <abbr class="tz" title="-05:00">Eastern Standard Time</abbr></div> <div>Profile details: <div>Profile id: <span class="uid">com.johndoe/profiles/johndoe</span></div> <div>Details are: <span class="class">Public</span></div> <div>Last updated: <abbr class="rev" title="2008-01-01T13:45:00">January 1st, 2008 - 13:45</abbr></div> </div> </div> </div>
Some parsers such as UfXtarct and Sumo already have this ability to parse only a fragement of HTML from a pgae, for other you can use a proxy service. It allows you to define a URL of a page and the ID of any element and it returns a HTML page containing just that element.
Current test methods
- IsEqualTo()
- isEqualToCaseInsensitive()
- IsEqualToISODate()
- IsEqualToPhoneNumbers()
- isEqualToGeo()
- IsTrue()
- IsFalse()
- HasProperty()
see also
- test-suite
- value-class-date-time-tests - which lists a bunch of test cases all marked up with the test-fixture poshformat
- poshformats