Page 1 of 1
Xspec unit testing
Posted: Tue May 03, 2016 6:06 pm
by DanielCDS
Does anyone know how to test this simple code using the XSpec in XSLT?
Code: Select all
<xsl:template match="@NameTitle">
<NameTitle Value="{if(. = ('Sir', 'Lady', 'Hon', 'R Hon')) then 'Other' else .}"
Description="{if(. = ('Sir', 'Lady', 'Hon', 'R Hon')) then . else ''}"/>
</xsl:template>
<xsl:template match="BusinessChannel/Contact/ContactPerson">
<PersonName>
<xsl:apply-templates select="@NameTitle"/>
<FirstName>
<xsl:value-of select="@FirstName"/>
</FirstName>
<Surname>
<xsl:value-of select="@Surname"/>
</Surname>
</PersonName>
</xsl:template>
Using Xspec is simple for testing functions from a beginner point of view but for templates that select attributes is not.
Re: Xspec unit testing
Posted: Thu May 05, 2016 10:18 am
by DanielCDS
I've done this for solving the problem:
Code: Select all
<x:scenario label="Scenario for testing template with match '@NameTitle' When processing a NameTitle attribute">
<x:scenario label="NameTitle = 'Sir'">
<x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='Sir']"/>
<x:expect label="Produce a NameTitle element with the Value='Other' and Description='Sir'">
<NameTitle Value="Other"
Description="Sir"/>
</x:expect>
</x:scenario>
<x:scenario label="NameTitle = 'Lady'">
<x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='Lady']"/>
<x:expect label="Produce a NameTitle element with the Value='Other' and Description='Lady'">
<NameTitle Value="Other"
Description="Lady"/>
</x:expect>
</x:scenario>
<x:scenario label="NameTitle = 'Hon'">
<x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='Hon']"/>
<x:expect label="Produce a NameTitle element with the Value='Other' and Description='Hon'">
<NameTitle Value="Other"
Description="Hon"/>
</x:expect>
</x:scenario>
<x:scenario label="NameTitle = 'R Hon'">
<x:context href="Test60%20-%20CAL.xml" select="//@NameTitle[.='R Hon']"/>
<x:expect label="Produce a NameTitle element with the Value='Other' and Description='R Hon'">
<NameTitle Value="Other"
Description="R Hon"/>
</x:expect>
</x:scenario>
<!--
<x:scenario label="NameTitle != ('Sir', 'Lady', 'Hon', 'R Hon')">
<x:context href="Test60%20-%20CAL.xml" select="//@NameTitle"/>
<x:expect label="Produce a NameTitle element with the Value !='Other'">
<NameTitle Value="..."
Description=""/>
</x:expect>
</x:scenario>-->
</x:scenario>
Re: Xspec unit testing
Posted: Thu May 05, 2016 12:02 pm
by alex_jitianu
Hi Daniel,
Thank you for posting the solution so others might benefit from it. A small tutorial on writing scenarios can be found in the
XSpec Wiki. Also, a good place to get in touch with people that have experience with XSpec is on the
XSpec discussion list.
Best regards,
Alex