Ant+JUnit+SeleniumでWEBアプリケーションのテストを書いてます。
アサーションがコケた時や例外時に出力にテスト中のURLを出力したいと思い、PlainJUnitResultFormatter
を上書きました。
フォーマッター自体は期待通り動いているのですが、multiple versions of ant detected in path for junit
というウォーニングが出ます。
下記のようなコマンドでテストを起動しています。
ant -f /Users/masamoto/Documents/repos/home/source/sites/selenium/build.xml -Dselenium.port=4444 -Dselenium.host=127.0.0.1 -Dinclude.path=/Users/masamoto/Documents/repos/home/source/sites/selenium/libs -Dsetting.path=/path/to/settings.yml -Dtest.class=jp.example.SomeTest -Dtest.methods=main
出力されるウォーニングは下記です。
test: [junit] WARNING: multiple versions of ant detected in path for junit [junit] jar:file:/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar!/org/apache/tools/ant/Project.class [junit] and jar:file:/Users/masamoto/Documents/repos/home/source/sites/selenium/libs/apache-ant/ant.jar!/org/apache/tools/ant/Project.class
ant経由で実行するとant.jarが自動で含まれるのかと思って、build.xmlに記述してある${include.path}
からant.jar
を取り除くと今度はコンパイルがコケます。
compile: [javac] Compiling 18 source files to /Users/masamoto/Documents/repos/home/source/sites/selenium/build [javac] /Users/masamoto/Documents/repos/home/source/sites/selenium/src/jp/sunrisedigital/selenium/JunitFormatter.java:14: error: cannot access BuildException [javac] public class JunitFormatter extends PlainJUnitResultFormatter { [javac] ^ [javac] class file for org.apache.tools.ant.BuildException not found [javac] 1 error
当然コマンドのjarをpathelement
に指定してやると問題なく動きますが、他の環境に配布した時に微妙なので引数で渡すようにしました。
<pathelement location="${ant.jar.path}" />
ant -f /Users/masamoto/Documents/repos/home/source/sites/selenium/build.xml -Dselenium.port=4444 -Dselenium.host=127.0.0.1 -Dinclude.path=/Users/masamoto/Documents/repos/home/source/sites/selenium/libs -Dsetting.path=/path/to/settings.yml -Dtest.class=jp.example.SomeTest -Dtest.methods=main -Dant.jar.path=/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar
これでウォーニングも消え、ちゃんと動くのですが、よくあるシチュエーションだと思うのでなんかもっとスマートな解決策があるような気がしたので質問させていただきました。よろしくお願いします。
build.xml
の内容をアップしておきます。
<?xml version="1.0" encoding="UTF-8" ?> <project name="sunrise.selenium" default="clean" basedir="."> <description> Seleniumのテスト郡 </description> <property name="path.build" location="build"/> <path id="test.classpath"> <pathelement location="${path.build}" /> <dirset dir="${include.path}/jetty/resources"/> <fileset dir="${include.path}"> <include name="**/*.jar"/> </fileset> <fileset dir="${include.path}/velocity"> <include name="*.jar"/> </fileset> <fileset dir="${include.path}/apache-ant"> <include name="*.jar"/> </fileset> </path> <target name="init"> <!-- Create the time stamp --> <tstamp/> <mkdir dir="${path.build}"/> </target> <target name="compile" depends="init" description="compile the source" > <javac srcdir="src" destdir="${path.build}" includeAntRuntime="no" encoding="utf-8" debug="true" debuglevel="lines,vars,source"> <classpath refid="test.classpath" /> </javac> </target> <target name="test" depends="compile" description="test the source"> <junit fork="yes" haltonfailure="yes"> <jvmarg value="-Dselenium.host=${selenium.host}"/> <jvmarg value="-Dselenium.port=${selenium.port}"/> <jvmarg value="-Dsetting.path=${setting.path}"/> <test name="${test.class}" unless="test.methods" /> <test name="${test.class}" methods="${test.methods}" if="test.methods" /> <formatter classname="jp.expample.selenium.JunitFormatter" usefile="false" /> <classpath refid="test.classpath" /> </junit> </target> <target name="clean" depends="test" description="clean up" > <delete dir="${path.build}"/> </target> </project>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2014/12/09 09:05
2014/12/12 14:20