2016-05-04 21 views
0

XSLTのXSpecを使ってこの単純なコードをテストする方法を知っている人はいますか? XSPECを使用してどのように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> 

は、ビューの初心者の観点から機能をテストするための単純であるが、属性を選択テンプレートの(今、私はそれを使用し始めているので、現時点では、少なくとも私にとっては)ないです。

例:これは簡単だった:

<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.P.私はOxygenXMLのXspecを使用しています。 https://github.com/expath/xspec/wiki/Writing-Scenarios#matching-scenarioshttps://github.com/expath/xspec/wiki/Writing-Scenarios#expectationsに基づいて

答えて

1

あなたはこれを使用すると、テスト・データを含むファイルtest.xmlを前提としてい

<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> 

を記述します。私もあなたが使用することができると思います

<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> 
+0

を使用して私が抱えていたエラーを解決することができます。あなたの回答から、私はマーティン・ホネンに感謝しました。 – DanielCSD

関連する問題