我想爲我的應用使用測試。我已經檢查了文檔以及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' **都不起作用。 –