unit testing - Why my XPath assertion test does pass in eXist-db? -


i have testing function takes document argument , transforms xml html. it, use tests. %test:assertxpath seems candidate in case. however, can’t understand behavior if use whole path.

my function:

xquery version "3.0";  module namespace cust = 'http://46.28.111.241:8081/exist/db/apps/myapp/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>                 </tei>',                 '/db/apps/myapp/resources/xslt/style-web.xsl')     %test:assertxpath('$result//@*')     %test:assertxpath('$result//*')     %test:assertxpath('$result//*[@class = "chapter"]')     %test:assertxpath('$result/html') function cust:transform($doc element(), $stylesheet xs:anyuri) node() {     let $stylesheet := doc($stylesheet)     let $document :=          (             <book n='1'>{($doc//tei:div[@n='1'])[1]}</book>         )     let $finale := transform:transform($document, $stylesheet, ())     return $finale }; 

the result:

<testsuites>     <testsuite package="http://46.28.111.241:8081/exist/db/apps/myapp/modules/cust"         timestamp="2016-03-17t09:14:40.107+01:00" failures="1" pending="0" tests="1" time="pt0.449s">         <testcase name="transform" class="cust:transform">             <failure message="assertxpath failed." type="failure-error-code-1">$result/html</failure>             <output>                 <html xmlns="http://www.w3.org/1999/xhtml">                     <head>                         <title/>                         <meta charset="utf-8"/>                     </head>                     <body>                         <div id="wrapper">                             <section xmlns:epub="http://www.idpf.org/2007/ops" epub:type="chapter">                                 <h1 class="chapter">heading</h1>                                 <p>paragraph</p>                             </section>                         </div>                     </body>                 </html>             </output>         </testcase>     </testsuite> </testsuites> 

it apparent 1 assertion not pass $result/html. why?

your missing namespace xpath assertion. <html> element producing in http://www.w3.org/1999/xhtml namespace.

so need change assertion either:

%test:assertxpath('$result/*:html') 

or need declare namespace prefix in prolog using declare namespace xhtml = "http://www.w3.org/1999/xhtml"; , assertion like:

%test:assertxpath('$result/xhtml:html') 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -