我想为我的应用使用测试。我已经检查了文档以及A. Retter在书中的特定章节。但是,我不知道如何使用其他类型的参数(特别是节点)。我的功能通常比转换数字或字符串的功能要高得多。例如,我想测试一个以文档(节点)作为参数的函数,并返回a)一个HTML文件; b)一个pdf文件。如何使用XQSuite测试eXist-db中的复杂功能
测试功能(在这里,我尝试测试上面提到的第一个功能):
xquery version "3.0";
module namespace cust = 'http://46.28.111.241:8081/exist/db/apps/karolinum-x/modules/cust';
declare namespace tei = 'http://www.tei-c.org/ns/1.0';
declare namespace test = 'http://exist-db.org/xquery/xqsuite';
declare
%test:args('<TEI xmlns="http://www.tei-c.org/ns/1.0">
<text>
<body>
<div n="1">
<head>Heading</head>
<p>paragraph</p>
</div>
</body>
</text>')
%test:assertXPath('$result/html')
function cust:transform($doc as node()*) as node() {
let $styles := doc('/db/apps/karolinum-x/resources/xslt/style-web.xsl')
let $document :=
(
<book n='1'>{($doc//tei:div[@n='1'])[1]}</book>
)
let $finale := transform:transform($document, $styles,())
return $finale
};
测试运行:
xquery version "3.0";
import module namespace test = 'http://exist-db.org/xquery/xqsuite' at 'resource:org/exist/xquery/lib/xqsuite/xqsuite.xql';
test:suite(inspect:module-functions(xs:anyURI('test-test.xqm')))
结果:
<testsuites>
<testsuite package="http://46.28.111.241:8081/exist/db/apps/karolinum-x/modules/cust" timestamp="2016-03-15T12:53:16.5+01:00" failures="0" pending="0" tests="1" time="PT0.002S">
<testcase name="transform" class="cust:transform">
<error type="err:XPTY0004" message="It is a type error if,
during the static analysis phase, an expression is found to have a
static type that is not appropriate for the context in which the
expression occurs, or during the dynamic evaluation phase, the dynamic
type of a value does not match a required type as specified by the
matching rules in 2.5.4 SequenceType Matching."/>
</testcase>
</testsuite>
</testsuites>
非常感谢提示,它真的帮了大忙!当然,我会解决这个问题。 –
剩下的唯一问题是我不能让'assertXPath'通过:)我会认为'($ result/html)'应该可以工作,但它不会。 –
哇,真的不明白为什么assert不起作用。 '$ result // @ *'工作,'$ result // *'工作,'$ result // * [@ class =“chapter”]'工作,'$ result/html **不**。我在这里错过了什么?这里不可能获取任何元素,即使是'$ result // html'或'$ result // body' **都不起作用。 –