如何实施 Xspec 单元测试?
How to implement a Xspec unit testing?
有谁知道如何使用 XSLT 中的 XSpec 测试这个简单的代码?
<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 | SalesChannel/LoanWriter">
<PersonName>
<xsl:apply-templates select="@NameTitle"/>
<FirstName>
<xsl:value-of select="@FirstName"/>
</FirstName>
<Surname>
<xsl:value-of select="@Surname"/>
</Surname>
</PersonName>
</xsl:template>
从初学者的角度来看,使用 Xspec 测试功能很简单,但对于 select 属性的模板则不然(至少目前对我来说是这样,因为现在我已经开始使用它了)。
例如:这很简单:
<xsl:function name="fn:RemoveSpace">
<xsl:param name="RemoveSpace"/>
<xsl:if test="$RemoveSpace != ''">
<xsl:value-of select="translate($RemoveSpace, ' ', '')"/>
</xsl:if>
</xsl:function>
<x:scenario label="Scenario for testing function RemoveSpace">
<x:call function="fn:RemoveSpace">
<x:param name="RemoveSpace" select="'Person Applicant'"/>
</x:call>
<x:expect label="Remove the white space">PersonApplicant</x:expect>
</x:scenario>
欢迎提出任何建议。
P.S。我正在使用来自 OxygenXML 的 Xspec。
基于https://github.com/expath/xspec/wiki/Writing-Scenarios#matching-scenarios and https://github.com/expath/xspec/wiki/Writing-Scenarios#expectations你会写
<x:scenario label="when processing a NameTitle attribute">
<x:context href="dir/test.xml" select="/foo/bar/@NameTitle"/>
<x:expect label="it should produce a NameTitle element">
<NameTitle Value="Other"
Description="Lady"/>
</x:expect>
</x:scenario>
这假设您有一个包含测试数据的文件 test.xml
。我想你也可以使用
<x:scenario label="when processing a NameTitle attribute">
<x:context select="@NameTitle">
<foo NameTitle="Sir"/>
</x:content>
<x:expect label="it should produce a NameTitle element">
<NameTitle Value="Other"
Description="Sir"/>
</x:expect>
</x:scenario>
有谁知道如何使用 XSLT 中的 XSpec 测试这个简单的代码?
<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 | SalesChannel/LoanWriter">
<PersonName>
<xsl:apply-templates select="@NameTitle"/>
<FirstName>
<xsl:value-of select="@FirstName"/>
</FirstName>
<Surname>
<xsl:value-of select="@Surname"/>
</Surname>
</PersonName>
</xsl:template>
从初学者的角度来看,使用 Xspec 测试功能很简单,但对于 select 属性的模板则不然(至少目前对我来说是这样,因为现在我已经开始使用它了)。
例如:这很简单:
<xsl:function name="fn:RemoveSpace">
<xsl:param name="RemoveSpace"/>
<xsl:if test="$RemoveSpace != ''">
<xsl:value-of select="translate($RemoveSpace, ' ', '')"/>
</xsl:if>
</xsl:function>
<x:scenario label="Scenario for testing function RemoveSpace">
<x:call function="fn:RemoveSpace">
<x:param name="RemoveSpace" select="'Person Applicant'"/>
</x:call>
<x:expect label="Remove the white space">PersonApplicant</x:expect>
</x:scenario>
欢迎提出任何建议。 P.S。我正在使用来自 OxygenXML 的 Xspec。
基于https://github.com/expath/xspec/wiki/Writing-Scenarios#matching-scenarios and https://github.com/expath/xspec/wiki/Writing-Scenarios#expectations你会写
<x:scenario label="when processing a NameTitle attribute">
<x:context href="dir/test.xml" select="/foo/bar/@NameTitle"/>
<x:expect label="it should produce a NameTitle element">
<NameTitle Value="Other"
Description="Lady"/>
</x:expect>
</x:scenario>
这假设您有一个包含测试数据的文件 test.xml
。我想你也可以使用
<x:scenario label="when processing a NameTitle attribute">
<x:context select="@NameTitle">
<foo NameTitle="Sir"/>
</x:content>
<x:expect label="it should produce a NameTitle element">
<NameTitle Value="Other"
Description="Sir"/>
</x:expect>
</x:scenario>