Javaにおける開発・Test(Unit/Web/負荷)環境のまとめ
うちの母親でも知っているJavaにおけるオープンソースを活用した開発環境・Test環境について調査及び評価する必要があり意外と労力を要したので
これからJavaでの開発において開発環境・Test環境を構築する際の参考になればとメモしておきます。
開発環境、ビルドツール、Test、Web Testing、負荷テストに重点を置いてあります。
インストールせずに使用出来るIDEのtIDEや、jythonでWebテストを記述するMaxQ、パフォーマンステストをjythonで記述するGrinder3、
Flexの負荷テストも可能なWebLOAD、Swingのテスト用のUISpec4j等、新しい発見もあったのでJava開発者の人にも参考になると嬉しいです。
それぞれライセンス、最新バージョン、個人的なお薦め度(5点満点)を合わせて明記してあります。
IDE
name | URL | Ver. | Licence | Recommend |
---|---|---|---|---|
Eclipse | http://www.eclipse.org/ | 3.4.1 | EPL | |
NetBeans | http://www.netbeans.org/ | 6.5 | CDDL/GPLV2 | |
EasyEclipse | http://www.easyeclipse.org/site/home/ | 1.3.1.1 | GPL | |
tIDE | http://snowmail.sn.funpic.de/tide/ | ? | GPL | |
jEdit | http://www.jedit.org/ | 4.3pre16 | GPL2.0 |
Build Tool
name | URL | Ver. | Licence | Recommend |
---|---|---|---|---|
Ant | http://ant.apache.org/ | 1.7.1 | ASL 2.0 | |
Maven | http://maven.apache.org/ | 2.0.9 | ASL 2.0 | |
Ivy | http://ant.apache.org/ivy/ | 2.0.0 | ASL 2.0 | |
Gant | http://gant.codehaus.org/ | 1.6.0 | ASL 2.0 |
ビルドツールまとめ
Ivyはビルドツールというより、ライブラリの依存関係を管理するもので、Antを使用して依存関係の管理を行う場合はIvyを採用してみるのが良い。
個人的には、Maven2に詳しい人がいればMaven2を採用しpom.xmlの作成を有識者に任せるのが良い。
GantはAntタスクによってビルドを実行するビルドツールだが、ビルドファイルをXML形式ではなくGroovyスクリプトによって記述することを可能にする。
Groovyが得意であれば、Gantも選択肢に入れて良い。GantにはIvy Toolもある。
Eclipseに初めから同梱されているのでAntは手軽に試しやすく、現場での使用は一番多い。
Mavenはプラグインが豊富なところはかなりお勧めだが、少々難しいところがある。
Unit Test
name | URL | Ver. | Licence | Recommend |
---|---|---|---|---|
JUnit | http://www.junit.org | 4.5 | CPL | |
TestNG | http://testng.org/ | 5.8 | ASL |
TestNG 補足
- TestNG Eclipse Plug-in http://testng.org/doc/eclipse.html
- TestNG IDEA Plug-in http://testng.org/doc/idea.html
- TestNG Maven Plug-in http://testng.org/doc/maven.html
- TestNG Ant Task http://testng.org/doc/ant.html
Web Testing
name | URL | Ver. | Licence | Recommend |
---|---|---|---|---|
Selenium | http://seleniumhq.org/ | ※ | ASL2.0 | |
Jamelon | http://jameleon.sourceforge.net/ | 3.3-RC1 | LGPL | |
JWebUnit | http://jwebunit.sourceforge.net/ | 2.1 | BSD | |
HttpUnit | http://www.httpunit.org/ | 1.7 | MIT | |
HtmlUnit | http://htmlunit.sourceforge.net/ | 2.4 | ASL2.0 | |
MaxQ | http://maxq.tigris.org/ | 1.0.3 | BSD | |
Canoo WebTest | http://webtest.canoo.com/ | 2.6 | ASL2.0 |
Selenium
- Selenium Remote Control http://seleniumhq.org/projects/remote-control/
- Selenium Grid http://selenium-grid.seleniumhq.org/
- CubicTest(Eclipse) http://cubictest.seleniumhq.org/
CubicTestは個人的に注目しています。CubicTestについては別途紹介しようと思います。
Jamelon
ダウンロードして解凍するだけで使えるGUIツールであり日本語の情報が少ないがお勧め。
plug-inが豊富でかつ作成可能。
- JUnit plug-in http://jameleon.sourceforge.net/junit-plugin.html
- Jiffe plug-in http://jameleon.sourceforge.net/jiffie-plugin/index.html
- Selenium plug-in http://jameleon.sourceforge.net/selenium-plugin/index.html
- Watij plug-in http://jameleon.sourceforge.net/watij-plugin/index.html
- Jagacy(3270) plug-in http://jameleon.sourceforge.net/jagacy-plugin/index.html
- HtmlUnit plug-in http://jameleon.sourceforge.net/htmlunit-plugin/index.html
- HttpUnit plug-in http://jameleon.sourceforge.net/httpunit-plugin/index.html
- jWebUnit plug-in http://jameleon.sourceforge.net/jwebunit-plugin/index.html
活動もかなり活発なので、注目していきたいと思います。
JWebUnit example
内部的にHtmlUnitを使用。
public class AppTest extends WebTestCase { public void testSample1() { setBaseUrl("http://jwebunit.sourceforge.net"); beginAt("/index.html"); assertTitleEquals("JWebUnit - JWebUnit"); } }
HttpUnit example
HTTPリクエスト/レスポンスを表すObjectを使用。
public static void main(String[] args) throws Exception{ WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest("http://www.httpunit.org/"); WebResponse res = wc.getResponse(req); System.out.println(res.getText()); }
HtmlUnit example
HTMLドキュメントを考慮した作り、HTMLドキュメントを表現したObjectを使用し、JWebUnitでも使用されている。
public void testSimple() throws Exception { WebClient webClient = new WebClient(); HtmlPage page = (HtmlPage)webClient.getPage(new URL("http://htmlunit.sourceforge.net/")); assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); }
MaxQ
maxq -r test.py
で実行可能(以下のscriptで動作)。
- テストスクリプトを記録するHTTP proxyとテストをプレイバックユーティリティを含んでいてプロキシレコーダは自動的にフォームにポストされた変数をストアします。
- MaxQ example test.py
from com.bitmechanic.maxq import HttpTestCase from junit.textui import TestRunner class SampleTest(HttpTestCase): def __init__(self): HttpTestCase.__init__(self, "") def testMaxq(self): print "Testing MaxQ" self.assertTrue(1 == 1) self.get("http://maxq.tigris.org/") #self.printResponse() print self.getResponse() if __name__ == '__main__': test = SampleTest() test.testMaxq()
個人的には、pythonの勉強がてらに良いと思います。
Canoo WebTest
各種設定ファイルを書くのが少々面倒。
負荷テスト
name | URL | Ver. | Licence | Recommend |
---|---|---|---|---|
JMeter | http://jakarta.apache.org/jmeter/ | 2.3.2 | ASL | |
WebLOAD | http://www.webload.org/ | 8.3 | GPL | |
Grinder3 | http://grinder.sourceforge.net/ | 3.1 | GPL | |
OpenSTA | http://www.opensta.org/ | 1.4.4 | GPL |
Grinder3
パフォーマンスやスケーラビリティだけでなく、検証可能性(戻り値が正しいことを検証すること)がある。
テストスクリプトは(COM/Javaオブジェクトと統合された)JavaScriptで記述され、アプリケーションの全ての層をテスト
するための複数のプロトコル(Web(AjaxをサポートしたREST/HTTP)、SOAP/XML、FTPやSMTP)をサポート。
テストスクリプトを実行するために使用されるJythonスクリプトエンジンのサポート。
HTTPテストはHTTPプロキシおよびその他の変更を通じて実行することができる。
Grinder3に関しては実際に以下のスクリプトでテストしてみました。
以下で起動
java -cp grinder.jar net.grinder.Console
java -cp grinder.jar -Dgrinder.logDirectory="log/log.txt" net.grinder.Grinder
- simple http sample
from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest test1 = Test(1, "Request resource") request1 = test1.wrap(HTTPRequest()) class TestRunner: def __call__(self): result = request1.GET("http://grinder.sourceforge.net/") writeToFile(result.text) def writeToFile(text): filename = grinder.getFilenameFactory().createFilename( "test", "-%d.html" % grinder.runNumber) file = open(filename, "w") print >> file, text file.close()
WebLOAD
オープンソース版では、いくつかの機能が限定されているが、もともと商用だっただけに成熟した製品かもしれません。
WebLOADは、Flexの負荷テストが出来るところも最大の魅力。
簡単な個人情報を入力すればダウンロード出来、インストールガイドのPDFとクイックスタートのHTMLが用意されている。
インストールにはpostgreSQLが必須で(インストールする際に自動でpostgreSQLもインストールされました)、実行するには同サイトからライセンスファイルをダウンロードし認証する必要がある。
AMFに加えてXML、SOAPとRESTを含む他のWebメッセージプロトコルもサポートされている。
動かしてみてかなり高機能な印象を受ける。
その他
Cactus
WEBコンテナ上で動作するテスティングフレームワーク
http://jakarta.apache.org/cactus/index.html
Eclipse TPTP
Eclipseでテストとパフォーマンスツールのプラットフォーム
http://www.eclipse.org/tptp/
FindBugs
Javaコードのバグ検出のために設計されたオープンソースの静的分析ツール
http://findbugs.sourceforge.net/
Hudson
CIツール。多くのオープンソースで利用されており、インストールの容易さ、拡張性の高さ
情報量の多さに定評がある。CIツールでは最もお勧め。日本人ならHudsonを使用しないとモグリ。
https://hudson.dev.java.net/
Continuum
Cobertura
Emma
FitNess
受け入れテスト。FIT+WikiサーバでWebからテスト記述出来、Excelシートからも貼り付けできる(動作確認していない)
http://fitnesse.org/
Stiq
StoryTestIQの略で、SeleniumとFitNessをマッシュアップ。
Story Test-Driven Development http://industrialxp.org/storyTdd.html
http://storytestiq.solutionsiq.com/wiki/Main_Page(動作確認していない)
DBUnit
データベースを操作するクラスのテストプログラムを作成するためのフレームワーク
http://www.dbunit.org/
DBMonster
データベースにテスト用ランダムデータを入れてくれるツール。
http://dbmonster.kernelpanic.pl/
EasyMock
モックオブジェクト
http://easymock.org/
jMock
モックオブジェクト
http://jmock.org/
XMLUnit
XMLテスティングフレームワーク。完全一致だけではなく類似一致の検証も行える。
http://xmlunit.sourceforge.net/
UISpec4j
Swing GUIアプリケーションのTestを簡単に行うためのライブラリでJUnit,TestNG上に構築されている。
※JDKのバージョン毎にバイナリが提供されており、5.xと6.xは2.0-RC3が最新。1.4.xは1.5。
http://www.uispec4j.org/
JTableの表示テストは以下の通り。
public void testContacts() { Table contacts = getMainWindow().getTable(); assertTrue(contacts.contentEquals(new Object[][]{ {"John", "12", Boolean.FALSE}, {"Sylvia", "43", Boolean.TRUE}, {"Bill", "31", Boolean.FALSE}})); }
id:kaisehさんにお勧めかも。