自分で解決策を思いつくことができたので、それを共有するのは良い考えだと思いました. このアプローチは完璧ではないかもしれませんが、うまくいったと思われる最初のアプローチです。改善点や提案を自由に投稿してください。
私がやったことを一言で言えば:
- 仮想フレームバッファであるXvfbのインスタンスを起動します
- JsTestDriver の使用:
- Firefox のインスタンスを仮想フレームバッファに (ヘッドレスで) 起動します
- Firefoxインスタンスをキャプチャしてテスト スイートを実行する
- JUnit 準拠のテスト結果を生成する .XML
- Bamboo を使用して結果ファイルを検査し、ビルドの成功または失敗を判断する
次に、より詳細なフェーズに進みます。これは、私のディレクトリ構造が最終的に次のようになったものです。
ライブラリ/
JsTestDriver.jar
テスト/
単位/
equiv.js
QUnitAdapter.js
jsTestDriver.conf
run_js_tests.sh
tests.js
テストレポート/
build.xml
ビルド サーバーで:
- Xvfb をインストールする (
apt-get install Xvfb
)
- Firefox をインストールする (
apt-get install firefox
)
ビルドするアプリケーションに:
サーバー: http://localhost:4224
ロード:
# QUnit アダプターをロードします (QUnit を使用しない場合は省略できます)
- qunit/equiv.js
- qunit/QUnitAdapter.js
# 自分自身をテストします (さらにファイルを追加する必要があります)
-tests.js
単体テストを実行してテスト結果を生成するためのスクリプト ファイルを作成します (Bash の例run_js_tests.sh
)。
#!/bin/bash
# directory to write output XML (if this doesn't exist, the results will not be generated!)
OUTPUT_DIR="../test-reports"
mkdir $OUTPUT_DIR
XVFB=`which Xvfb`
if [ "$?" -eq 1 ];
then
echo "Xvfb not found."
exit 1
fi
FIREFOX=`which firefox`
if [ "$?" -eq 1 ];
then
echo "Firefox not found."
exit 1
fi
$XVFB :99 -ac & # launch virtual framebuffer into the background
PID_XVFB="$!" # take the process ID
export DISPLAY=:99 # set display to use that of the xvfb
# run the tests
java -jar ../lib/JsTestDriver.jar --config jsTestDriver.conf --port 4224 --browser $FIREFOX --tests all --testOutput $OUTPUT_DIR
kill $PID_XVFB # shut down xvfb (firefox will shut down cleanly by JsTestDriver)
echo "Done."
スクリプトを呼び出す Ant ターゲットを作成します。
<target name="test">
<exec executable="cmd" osfamily="windows">
<!-- This might contain something different in a Windows environment -->
</exec>
<exec executable="/bin/bash" dir="test" osfamily="unix">
<arg value="run_js_tests.sh" />
</exec>
</target>
最後に、Bamboo ビルド プランにtest
ターゲットの呼び出しと JUnit テスト結果の検索の両方を指示します。ここでは、デフォルトで"**/test-reports/*.xml"
問題ありません。