[Testing XML] XUnit, your new companion...

P

Philippe Poulard

As a Java programmer, you ought to be interested by this new tool that
can check your Java programs that are producing XML datas or fragments

XUnit has been announced with the new release of RefleX, the Active Tags
engine.

http://reflex.gforge.inria.fr/xunit.html

XUnit is to XML-oriented Programming as JUnit is to Java programs : you
run the program to test with given datas, and check that the result get
are those expected.

The programs that you can test with XUnit are :
-Active Tags programs, that is to say programs made of XML tags
-XSLT stylesheets : XUnit can help you to test your templates individually
-Java programs that are dealing with XML datas : just expose your class
as a tag inside the engine and you will be able to test it easily with XUnit

Like JUnit, there are assertions that check basic types such as :
<xunit:assert-boolean-equals>,
<xunit:assert-number-equals>,
and <xunit:assert-string-equals>.
Unlike JUnit, there are also assertions that check types related to XML
such as :
<xunit:assert-node-equals>
and <xunit:assert-attributes-equals>.
There is also a mean for testing XSLT templates with
<xunit:apply-xslt-template>.

Example :

<xunit:test-case name="myTest" label="My test">
<!--run whatever to test here...-->
<do:it-like-this/>
<!--...say that this application is producing an XML file-->

<!--retrieve the result and the output expected-->
<xcl:parse name="result" source="purchase-order.xml"/>
<xcl:parse name="output-expected"
source="purchase-order-expected.xml"/>
<!--check if they are equals-->
<xunit:assert-node-equals result="{ $result }" expected="{
$output-expected }" recurse="true"/>
</xunit:test-case>

If some nodes differ, you'll have the differences notified in the error
report that you can transform to HTML, as shown in the tutorial
available with the full distribution of RefleX.

If you have a Java program that produce XML datas, the best way is to
expose it as a tag : <do:it-like-this/>

Enjoy !

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top