请帮助我学习xspec语法。我希望将测试文件中的值与常数:测试文件进行比较:
<?xml version='1.0' encoding='ISO-8859-5'?>
<List>
<M_INSDES>
<S_UNH>
<D_0062>3600</D_0062>
<C_S009>
<D_0065>INSDES</D_0065>
<D_0052>D</D_0052>
<D_0054>96A</D_0054>
<D_0051>UN</D_0051>
<D_0057>EAN001</D_0057>
</C_S009>
</S_UNH>
</M_INSDES>
</List>下列方案如预期的那样工作:
<x:scenario label="Scenario for testing an EDIFACT document type">
<x:context href="test.xml" select="/List/M_INSDES/S_UNH/C_S009/D_0065">
</x:context>
<x:expect label="The result of testing EDIFACT document type">INSDES</x:expect>
</x:scenario>

但是,带有多个值的场景失败了:
<x:scenario label="Scenario for testing an EDIFACT document type for inbound file">
<x:context href="test.xml" select="/List/M_INSDES/S_UNH/C_S009">
</x:context>
<x:expect label="Message type identifier" test="D_0065 = 'INSDES'"></x:expect>
<x:expect label="Message type version number" test="D_0052 = 'D'"></x:expect>
<x:expect label="Message type release number" test="D_0054 = '96A'"></x:expect>
</x:scenario>

如何使用C_S009检查节点<x:expect test = ""/>的三个值?
:添加了xsl样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="myfunctions"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>发布于 2018-05-09 07:57:59
我认为您所做的一切都是正确的,但是相对xpath的上下文是错误的。尝试在这样的expect 元素中使用绝对路径,并在中选择根元素:
<x:scenario label="Scenario for testing an EDIFACT document type for inbound file">
<x:context href="testdata.xml" select="/">
</x:context>
<x:expect label="Message type identifier" test="/List/M_INSDES/S_UNH/C_S009/D_0065 = 'INSDES'"></x:expect>
<x:expect label="Message type version number" test="/List/M_INSDES/S_UNH/C_S009/D_0052 = 'D'"></x:expect>
<x:expect label="Message type release number" test="/List/M_INSDES/S_UNH/C_S009/D_0054 = '96A'"></x:expect>
</x:scenario>我认为相对路径不起作用,因为样式表在匹配根元素时只复制完整的文档。在带有错误的XSpec报告中,可以看到具有相对路径的测试结果只是元素的字符串值。
在发布样式表之前,我使用了一个带有递归“复制所有节点”模板的样式表。
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>有了这个样式表,相对路径就能正常工作。
<x:scenario label="Scenario for testing an EDIFACT document type for inbound file">
<x:context href="testdata.xml" select="/List/M_INSDES/S_UNH/C_S009">
</x:context>
<x:expect label="Message type identifier" test="C_S009/D_0065 = 'INSDES'"></x:expect>
<x:expect label="Message type version number" test="C_S009/D_0052 = 'D'"></x:expect>
<x:expect label="Message type release number" test="C_S009/D_0054 = '96A'"></x:expect>
</x:scenario>发布于 2018-05-09 20:57:14
您能发布用XSpec测试测试的XSLT代码吗?如果没有XSLT,就很难再现它。
如果您正在测试一个原子值(在您的示例中是一个字符串),您可能对使用select元素的x:expect属性感兴趣,如XSpec文档中所描述的那样。
https://stackoverflow.com/questions/50236220
复制相似问题