Skip to content

Commit

Permalink
Fix: テストスクリプトを引数なしで実行すると NullPointerException が発生する (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ototadana committed May 27, 2015
1 parent 4203d7e commit cf36007
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FixtureBookRunner

ダウンロード
------------
* <http://xpfriend.com/fixture-book/fixture-book-runner-1.0.zip>
* <http://xpfriend.com/fixture-book/fixture-book-runner-1.1.zip>


必須ソフトウェア
Expand Down
2 changes: 1 addition & 1 deletion doc/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Exec
----
### 機能
引数で指定されたフォルダ及びその配下のフォルダに存在するテスト実行ファイルを全て実行する。
`testtest` スクリプトから呼び出されているコマンド。
`testexec` スクリプトから呼び出されているコマンド。

### 呼び出し形式
```bash
Expand Down
14 changes: 7 additions & 7 deletions doc/Setup-Unix.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ FixtureBookRunner - Unix 環境でのセットアップ
```

2. 展開すると **fixture-book** という名前のフォルダができるので、
その中にある **testtest** スクリプトに実行権を付与する。
その中にある **testexec** スクリプトに実行権を付与する。

```bash
chmod +x fixture-book/testtest
chmod +x fixture-book/testexec
```

3. testtest スクリプトを任意のフォルダから実行できるようにするため、
3. testexec スクリプトを任意のフォルダから実行できるようにするため、
環境変数 **PATH****fixture-book** を追加する。

**~/** に展開した場合の例:
Expand All @@ -33,8 +33,8 @@ FixtureBookRunner - Unix 環境でのセットアップ
### (参考) fixture-book フォルダ構成

─fixture-book/
testtest ... テスト実行用スクリプト(Unix用)
testtest.bat ... テスト実行用バッチファイル(Windows用)
testexec ... テスト実行用スクリプト(Unix用)
testexec.bat ... テスト実行用バッチファイル(Windows用)
│ *-unix-example.zip ... Unix環境用サンプル
│ *-windows-example.zip ... Windows環境用サンプル
Expand Down Expand Up @@ -76,11 +76,11 @@ fixture-book/*-unix-example.zip は、Unix環境用テストサンプルです
chmod +x fixture-book-example/app-test/tests/*
```

3. テスト実行環境に移動して、`testtest` コマンドを実行する。
3. テスト実行環境に移動して、`testexec` コマンドを実行する。

```bash
cd fixture-book-example/app-test
testtest
testexec
```

4. 実行終了すると **reports** フォルダにテスト結果レポート(XMLファイル)
Expand Down
10 changes: 5 additions & 5 deletions doc/Setup-Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ FixtureBookRunner - Windows 環境でのセットアップ
------------
1. ダウンロードした zip ファイルを任意の場所に展開する。
2. 展開すると **fixture-book** という名前のフォルダができるので、
その中にある **testtest.bat** を任意のフォルダから実行できるようにするため、
その中にある **testexec.bat** を任意のフォルダから実行できるようにするため、
環境変数 **PATH****fixture-book** を追加する。

### (参考) fixture-book フォルダ構成

─fixture-book/
testtest.bat ... テスト実行用バッチファイル(Windows用)
testtest ... テスト実行用スクリプト(Unix用)
testexec.bat ... テスト実行用バッチファイル(Windows用)
testexec ... テスト実行用スクリプト(Unix用)
│ *-windows-example.zip ... Windows環境用サンプル
│ *-unix-example.zip ... Unix環境用サンプル
Expand Down Expand Up @@ -46,11 +46,11 @@ fixture-book\*-window-example.zip は、Window環境用テストサンプルで
├── reports/ ... テスト結果レポート
└── tests/ ... テスト実行用ファイル(バッチファイル、Excelファイル)

2. テスト実行環境に移動して、`testtest` コマンドを実行する。
2. テスト実行環境に移動して、`testexec` コマンドを実行する。

```bat
cd fixture-book-example\app-test
testtest
testexec
```

3. 実行終了すると **reports** フォルダにテスト結果レポート(XMLファイル)
Expand Down
20 changes: 10 additions & 10 deletions doc/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ Excel ファイル記述内容は以下の通りです。
set APP_DIR=c:\Users\Owner\app
```

2. **tutorial** フォルダ上で、**testtest** コマンドを実行します。
2. **tutorial** フォルダ上で、**testexec** コマンドを実行します。

引数なしで `testtest` と実行するか、`testtest tests` というふうに、
引数なしで `testexec` と実行するか、`testexec tests` というふうに、
テスト実行用Excelファイルを格納したフォルダを引数に指定して実行します。

実行終了後、**reports** フォルダに JUnit 形式の XML ファイルとしてテスト結果が出力されます。
もし引数なしで実行した場合は、reports フォルダに **tests.HelloTest.xml** というファイルができます。


### (参考) testtest コマンドの動作について
testtest コマンドは引数で指定したディレクトリに含まれるテスト実行ファイルを全て実行します。
従って、`testtest tests` で実行すれば、**tests** フォルダに含まれるファイルが実行されます。
### (参考) testexec コマンドの動作について
testexec コマンドは引数で指定したディレクトリに含まれるテスト実行ファイルを全て実行します。
従って、`testexec tests` で実行すれば、**tests** フォルダに含まれるファイルが実行されます。

#### 実行対象となるファイルの種類
* ファイル名の末尾が以下のものに一致する場合、テスト実行ファイルとみなされ実行されます。
Expand All @@ -130,13 +130,13 @@ testtest コマンドは引数で指定したディレクトリに含まれる
#### 実行対象ファイルの検索方法と実行順
* 001Test.xlsx と 001Test.bat というふうに同じ名前で拡張子のみが異なるファイルが存在する場合、
001Test.bat が実行され、001Test.xlsx は実行されません。
* testtest の引数で指定したフォルダの中に別のフォルダがあり、
* testexec の引数で指定したフォルダの中に別のフォルダがあり、
その中にテスト実行ファイルが存在する場合も実行対象となります。
* testtest の引数で指定されたフォルダの中に複数のテスト実行ファイルが存在する場合、
* testexec の引数で指定されたフォルダの中に複数のテスト実行ファイルが存在する場合、
アルファベットの昇順に実行されます。
* testtest の引数で指定されたフォルダの中に別のフォルダが存在する場合、
* testexec の引数で指定されたフォルダの中に別のフォルダが存在する場合、
より階層の浅いフォルダに含まれるファイルを先に実行します。
* testtest の引数でフォルダを指定しなかった場合、現在のフォルダが指定されたものとみなされます。
* testexec の引数でフォルダを指定しなかった場合、現在のフォルダが指定されたものとみなされます。


5. 設定ファイルについて
Expand Down Expand Up @@ -175,7 +175,7 @@ port | FixtureBook 実行サーバーのポート番号(デフォルト
102-ExampleJobTest.xlsx ... テスト実行用FixtureBookファイル(その2)
999-ShutdownH2DatabaseTest ... テスト用データベース停止スクリプト

**app-test** フォルダで `testtest` コマンドを実行すればテスト実行できます。
**app-test** フォルダで `testexec` コマンドを実行すればテスト実行できます。
その際、以下の順番でテスト実行されます。

テスト実行ファイル | 実行内容
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.xpfriend</groupId>
<artifactId>fixture-book-runner</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>FixtureBookRunner</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.TreeMap;

import com.xpfriend.junk.ConfigException;
import com.xpfriend.junk.Strings;

/**
Expand All @@ -46,7 +47,13 @@ public int compare(String a, String b) {
* @param path 実行可能なファイルを格納するディレクトリのパス。
*/
public ExecutableFilesDirectory(String path) {
this.executableFiles = getExecutableFiles(new File(path).getAbsoluteFile());
File directory = new File(path);
if(!directory.isDirectory()) {
throw new ConfigException(
"M_FixtureBookRunner_ExecutableFilesDirectory_Not_Directory",
directory.getAbsolutePath());
}
this.executableFiles = getExecutableFiles(directory.getAbsoluteFile());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ M_FixtureBookRunner_Exec_CannotDeleteFile=%1$s\u3092\u524a\u9664\u3067\u304d\u30
M_FixtureBookRunner_Exec_TestFailed=%1$s\u306e\u5b9f\u884c\u304c\u5931\u6557\u3057\u307e\u3057\u305f\uff08\u7d42\u4e86\u30b3\u30fc\u30c9\uff1a%2$s\uff09
M_FixtureBookRunner_Exec_TestCaseName=%1$s\u306e\u5b9f\u884c\u304c\u6b63\u5e38\u7d42\u4e86\u3059\u308b\u3053\u3068
M_FixtureBookRunner_Expect_Command_Failed=\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u306b\u5931\u6557\u3057\u307e\u3057\u305f\uff08\u7d42\u4e86\u30b3\u30fc\u30c9\uff1a%1$s\uff09
M_FixtureBookRunner_ExecutableFilesDirectory_Not_Directory=%1$s\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u306f\u3042\u308a\u307e\u305b\u3093
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/test/java/com/xpfriend/fixture/runner/ExecTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,14 @@ class ExecTest extends Specification {
suite.testcase.size() == 1
suite.testcase[0].error[0].type == "java.io.IOException"
}

def "Execコンストラクタの引数がディレクトリでない場合ConfigExceptionが発生する"() {
setup:
print CLIBase
when:
Exec exec = new Exec("-")
then:
ConfigException e = thrown()
e.toString().indexOf("-") > -1
}
}

0 comments on commit cf36007

Please sign in to comment.