流れ
Eclipseでごにょごにょするのが嫌だったので。
AntでJUnit 4.10のテストを実行する - Symfoware
ソースコードは↑のリンクを参照した。
以下ディレクトリ構成。
$ tree -a -I .git
.
├── .gitignore
├── .travis.yml
├── README.md
├── build
│ └── sample
│ └── Main.class
├── build.xml
├── dist
│ └── sample-20140429.jar
├── lib
│ └── junit-4.10.jar
├── src
│ ├── main
│ │ └── java
│ │ └── sample
│ │ └── Main.java
│ └── test
│ └── java
│ └── sample
│ └── MainTest.java
└── testbuild
└── sample
└── MainTest.class
自分で作ったソースコードはGitHubにあげました。
ソースコードを書いて、JUnitのjarファイルをおいて、build.xmlを書いて、ant dist。
するとこんな感じ。
$ ant dist master ‹system›
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Buildfile: /Users/shige/projects/junit-ant/build.xml
init:
[mkdir] Created dir: /Users/shige/projects/junit-ant/build
[mkdir] Created dir: /Users/shige/projects/junit-ant/testbuild
compile:
[javac] Compiling 1 source file to /Users/shige/projects/junit-ant/build
[javac] Compiling 1 source file to /Users/shige/projects/junit-ant/testbuild
test:
[junit] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[junit] Testsuite: sample.MainTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.091 sec
[junit]
[junit] Testcase: testAdd took 0.01 sec
dist:
[mkdir] Created dir: /Users/shige/projects/junit-ant/dist
[jar] Building jar: /Users/shige/projects/junit-ant/dist/sample-20140429.jar
BUILD SUCCESSFUL
Total time: 8 seconds
テストは通っているぽい。
なお、GitHubにアップするにあたり、TravisCIでCIをやるようにしてみました。
こんな感じでさくっと書いてみます。
Travis CI: Building a Java project
language: java script: - ant dist
まとめ
- ソースコードを書く
- jarファイルを置く
- build.xmlを書く
- ant実行
この流れを覚えておきたいよ。
追記
開発環境
- Mac OSX 10.9.2
- Apache Ant(TM) version 1.9.3 compiled on December 23 2013
- java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
- junit-4.10