Sunday, August 10, 2008

XHarness How To: Using ignore ANSI.


With the release of XHarness 1.0-beta2 I have decided to write a quick how-to for using the new ignore ANSI feature. The reason for this feature addition was to resolve the issue separation of content and presentation.

When testing an application we are generally concerned with the correct content of output, presentation details such as bold text or text colour markups may not be essential to asserting a correct response.

Take for example an application that takes in a username and reports back "Hello username, welcome to example1 program". The general format of the XHarness definition to test this program would be:

<xh-execbg executable="${path.to.app}/bin/example1"
processname="example1"
dir="${path.to.app}"/>
<arg line="foobar"/>
</xh-execbg>
<assert timeout="10" erroronfail="true">
<and>
<outputcontains stream="stdout"
task="xh-execbg">Hello foobar, welcome to example1 program.</outputcontains>
</and>
</assert>


Given the input "foobar" we expect the output to be "Hello foobar, welcome to example1 program." In this case XHarness will run the demo application, assert the correct output was received, then report success.

Now what happens if we modify example1 program to print out username in bold? The above XHarness definition would report a failed assertion. The reason for this is that the output contains method will be looking for plain text, the markup to present bold text would violate the matching specified.

To simplify working with output that may include ANSI markups the ignoreansi attribute was added. The default behavior is to not ignore ANSI text markup control characters, thus allowing developers to consider these markups part of a correct response. If the developer however would like to ignore such presentation details and just focus on the content of a response they may alter their output contains fragments to the following:

<assert timeout="10" failonerror="true">
<and>
<outputcontains stream="stdout"
task="xh-execbg"
ignoreansi="true" >Hello foobar, welcome to example1 program.</outputcontains>
</and>
</assert>

This time when XHarness processes the output from example1 program it will assert a match successfully.

For more information on using XHarness please see the XHarness web site: http://xharness.codehaus.org

No comments: