Maven を使用して管理している小さなコマンド ライン ユーティリティ プロジェクトがあります。このユーティリティは、Velocity テンプレートにデータを入力し、結果を新しいファイルにダンプするための非常にシンプルなアプリです。私の問題は、Velocity テンプレートをどこに置くかです。それらを に配置するとsrc/test/resources/foo/bar/baz
、テスト用のファイルとテスト中のクラスが配置されてmvn test
いる に明確にあるにもかかわらず、参照されたテンプレートが見つからないため失敗します。テンプレートをプロジェクトの最上位ディレクトリに配置すると、テストはパスしますが、Maven プロジェクト構造に従っていないため、実際にパッケージ化された .jar ファイルが機能しないのではないかと思います。私は何が欠けていますか?target/classes/foo/bar/baz
.class
アップデート:
テスト中のメソッド:
public final void mergeTemplate(final String templateFileName, final Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, Exception {
Velocity.init();
Velocity.mergeTemplate(templateFileName, Charset.defaultCharset().name(), context(), writer);
}
試験方法:
@Test
public void testMergeTemplate() throws Exception {
final FooGenerator generator = new FooGenerator();
final StringWriter writer = new StringWriter();
generator.mergeTemplate("foo.yaml", writer);
Assert.assertEquals("Something went horribly, horribly wrong.", EXPECTED_RESULT, writer.toString().trim());
}
私が配置してテストをパスさせることができる唯一の場所foo.yaml
は、プロジェクトのルート ディレクトリ、つまり と のピアとしてsrc
ですtarget
。