Forums: Open Discussion (Thread #24296)

【バッチFW】単体テストでのファイル内容の取得方法について (2009-10-20 15:17 by Anonymous #46554)

お世話になります。

単体テストを行っているのですが、単体テストクラスから、ファイルの情報を取得するにはどうすればよろしいのでしょうか。

http://sourceforge.jp/forum/message.php?msg_id=41385

を参照に通常のDBの値などは設定ファイル等に設定しqueryDAO等からexecuteForList等から情報を取得できるんですが。。。。

●要約すると、単体テストクラスからFixedFileQueryDAO(固定長ファイル形式)のDAOを使用して行数分値をデータを取得したいのですが、どうすればいいかわかりません。

下記、単体テストクラスからしたいことのサンプル
------------------------------------------

FileLineIterator<TelegramDto> fileLineIterator = fixedFileQueryDAO.execute(inputFileName, TelegramDto.class);

// 繰り返し
while(fileLineIterator.hasNext()) {

...test logic execute

}
------------------------------------------

どうぞよろしくお願い致します。

Reply to #46554×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 【バッチFW】単体テストでのファイル内容の取得方法について (2009-10-20 17:49 by taromaru #46557)

http://sourceforge.jp/forum/message.php?msg_id=41385
が出来たのであれば、
fixedFileQueryDAOを使用するのに必要な定義
・Bean定義
・テストクラスのフィールドとsetter
を追加すれば動作すると思います。
(ただし未検証です。)

1. /batchapps/template/FileAccessBean.xmlを追加で取り込む。

@Override
protected String[] doGetConfigLocations() {
return new String[] {"/dao-test.xml"};

return new String[] {"/dao-test.xml", "/template/FileAccessBean.xml"};
}
※「/batchapps」はソースフォルダの名前なので、クラスパス上は現れません。


2. テストクラスにフィールドとsetterを追加する。

private FixedFileQueryDAO fixedFileQueryDAO = null;
public void setFixedFileQueryDAO(FixedFileQueryDAO fixedFileQueryDAO){
this.fixedFileQueryDAO = fixedFileQueryDAO;
}
※このsetterの名前によって、bean定義された"fixedFileQueryDAO"がインジェクションされます。
大文字小文字を間違うとインジェクションされないので注意してください。
Reply to #46554

Reply to #46557×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 【バッチFW】単体テストでのファイル内容の取得方法について (2009-10-20 21:31 by Anonymous #46562)

早速のご回答ありがとうございます。

上記の通りしただけで、上手くできました。

>return new String[] {"/dao-test.xml", "/template/FileAccessBean.xml"};

このように設定すればよかったんですね。

本当にありがとうございました。

また何かありましたら、よろしくお願い致します。


Reply to #46554

Reply to #46562×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login