第12章 テスト
12.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>