Tigerには良さそうなテスティングフレームワーク
アノテーションを効果的に使っている。
テストクラスは、JUnitだとtest...だけど、testNGだと、@Test annotation。
setUpやtearDownは@Configuration annotationで指定。
import com.beust.testng.annotations.*; public class SimpleTest { @Configuration(beforeTestClass = true) public void setUp() { // code that will be invoked when this test is instantiated } @Test(groups = { "functest" }) public void testItWorks() { // your test code } }
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" > <suite name="My suite"> <test name="Simple example"> <classes> <class name="example1.Test1" /> </classes> </test> </suite>
設定ファイルでは、メソッド単位など、細かなグループ分けなどが出来るみたい。
さらにantタスクも用意されている。
<taskdef name="testng" classname="com.beust.testng.TestNGAntTask" classpathref="cpath"/> <path id="runpath"> <path refid="cpath"/> <pathelement location="classes"/> </path> <target name="test" depends="compile"> <echo message="running tests"/> <testng fork="yes" classpathref="runpath" outputDir="test-output"> <fileset dir="src" includes="testng.xml"/> <jvmarg value="-ea" /> </testng> </target>
実行後、${outputDir}/index.html
にテストレポートが出力される。
一番気に入ったのは、例外検査。
@ExpectedExceptions(NumberFormatException.class)
こういったアノテーションだけで例外検査が出来ると。
うん。JUnitよりいい気がするなあ。もうちょっと試してみよう。