eclipseでunitテストを書く前に最低限やっておくこと
1. quick-junitを入れる
http://quick-junit.sourceforge.jp/
- テスティングペアを開く: Ctrl + 9
- JUnit テスト:Ctrl + 0
で操作できる。
2. static importの展開をやめる
参考:http://d.hatena.ne.jp/Yamashiro0217/20090409/1239242490
Preferenceの[Java]-[Code Style]-[Organize Imports]の「Number of static imports needed for .*」を1に設定する。
3. GanymedeのテンプレートにassertThatとか追加する
参考:http://d.hatena.ne.jp/ashigeru/20090216/1234756826
Preferencesの[Java]-[Editor]-[Templates]から[New...]で追加できる。
assertThat
${assert:importStatic('org.junit.Assert.*','org.hamcrest.CoreMatchers.*')} assertThat(${actual}, ${matcher})${cursor}
なるべく短い名前で参照したいのでnameはatとかにしておく。
after
@${After:newType(org.junit.After)} public void tearDown() throws Exception { ${cursor} }
必要ならAfterClass、BeforeClassも追加する。ちなみにデフォルトでTestが以下のように登録されているので、これも活用する。
@${testType:newType(org.junit.Test)} public void ${testname}() throws Exception { ${staticImport:importStatic('org.junit.Assert.*')}${cursor} }