Show Table of Contents
第11章 テスト
11.1. 単体テスト
Smooks で単体テストを実行するのは比較的簡単です。
public class MyMessageTransformTest
{
@Test
public void test_transform() throws IOException, SAXException
{
Smooks smooks = new Smooks(
getClass().getResourceAsStream("smooks-config.xml") );
try {
Source source = new StreamSource(
getClass().getResourceAsStream("input-message.xml" ) );
StringResult result = new StringResult();
smooks.filterSource(source, result);
// compare the expected xml with the transformation result.
XMLUnit.setIgnoreWhitespace( true );
XMLAssert.assertXMLEqual(
new InputStreamReader(
getClass().getResourceAsStream("expected.xml")),
new StringReader(result.getResult()));
} finally {
smooks.close();
}
}
}
上記のテストケースでは、 XMLUnit というソフトウェアが使用されています (詳細は http://xmlunit.sourceforge.net を参照してください)。
注記
上記のテストでは次のような Maven の依存関係が必要になります。
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.1</version>
</dependency>
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.