지속적 통합 빌드에서 헤드리스로 JavaScript 단위 테스트 실행
지속적 통합 시스템 ( Atlassian Bamboo 2.5) 에서 실행되는 웹앱 빌드 계획이 있습니다. QUnit 기반 JavaScript 단위 테스트를 빌드 계획 에 통합 하여 각 빌드에서 Javascript 테스트가 실행되고 Bamboo가 테스트 결과를 해석 할 수 있도록해야합니다.
가급적이면 외부 서버에 대한 연결이 필요하지 않도록 빌드 프로세스를 "독립형"으로 만들 수 있기를 바랍니다. 이것을 달성하는 방법에 대한 좋은 아이디어? 빌드 프로세스를 실행하는 CI 시스템은 Ubuntu Linux 서버에 있습니다.
내가 스스로 해결책을 내놓았 기 때문에 그것을 공유하는 것이 좋은 생각이라고 생각했습니다. 접근 방식이 완벽하지는 않을 수도 있지만 작동하는 것처럼 보이는 첫 번째 방법입니다. 개선 사항 및 제안 사항을 자유롭게 게시하십시오.
간단히 말해서 내가 한 일 :
- 가상 프레임 버퍼 인 Xvfb 인스턴스 시작
- JsTestDriver 사용 :
- Firefox 인스턴스를 가상 프레임 버퍼로 실행 (헤드리스)
- Firefox 인스턴스를 캡처하고 테스트 스위트를 실행하십시오.
- JUnit 호환 테스트 결과 .XML 생성
- Bamboo를 사용하여 결과 파일을 검사하여 빌드를 통과하거나 실패합니다.
다음으로 더 자세한 단계를 살펴 보겠습니다. 이것은 내 디렉토리 구조가 다음과 같이 생겼습니다.
lib / JsTestDriver.jar 테스트/ qunit / equiv.js QUnitAdapter.js jsTestDriver.conf run_js_tests.sh tests.js 테스트 보고서 / build.xml
빌드 서버에서 :
- Xvfb (
apt-get install Xvfb
) 설치 - Firefox (
apt-get install firefox
) 설치
빌드 할 애플리케이션으로 :
- JsTestDriver 설치 : http://code.google.com/p/js-test-driver/
- QUnit 어댑터를 추가
equiv.js
하고QUnitAdapter.js
- JsTestDriver 구성 (
jsTestDriver.conf
) :
- QUnit 어댑터를 추가
서버 : http : // localhost : 4224 하중: # QUnit 어댑터로드 (QUnit를 사용하지 않는 경우 생략 가능) -qunit / equiv.js -qunit / QUnitAdapter.js # 자체 테스트 (파일을 더 추가해야 함) -tests.js
단위 테스트를 실행하고 테스트 결과를 생성하기위한 스크립트 파일을 만듭니다 (예 run_js_tests.sh
: Bash, ).
#!/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>
Finally, tell the Bamboo build plan to both invoke the test
target and look for JUnit test results. Here the default "**/test-reports/*.xml"
will do fine.
For anyone interested in running their Jasmine BDD specs headlessly in maven, you might be interested in the jasmine-maven-plugin I maintain:
http://github.com/searls/jasmine-maven-plugin
As an alternative, you could also try TestSwarm. I've got it up and running using QUnit to run my JS tests.
I've played around with a number of solutions over the past year but I didn't find anything in the ballpark of Karma (formerly testacular). Give it a try
http://karma-runner.github.com/
You may be able to use rhino, the headless browser, to run your unit tests on your CI machine. Of course, the disadvantage here is that it won't find bugs specific to browser X... but it does beat installing 2-3 OSes on your CI box, to cover all the main platforms...
But yes, this kind of sucks... but it might work just well enough in a CI scenario.
I have used maven and junit to call rhino. It is not elegant, but I use it to test basic services and utility code.
It requires mocking unsupported classes, like XHR with Java libraries.
I found that it is best code everything in javascript (tests, etc) and only use junit for build organization and a hook into the CI.
I'd like to see if JsTestDriver can do it though. Or mocha w/ a junit reporter.
JS Test Runner is a pretty good solution. It uses PhantomJS and QUnit.
'program story' 카테고리의 다른 글
iPhone / Android 애플리케이션 개발을위한 멀티 플랫폼 프레임 워크가 있습니까? (0) | 2020.12.10 |
---|---|
배치 파일의 인쇄 시간 (밀리 초) (0) | 2020.12.10 |
Java 원격 디버깅, 기술적으로 어떻게 작동합니까? (0) | 2020.12.09 |
C # 4.0, 선택적 매개 변수 및 매개 변수가 함께 작동하지 않음 (0) | 2020.12.09 |
foreach는 PHP에서 배열 순서로 반복되도록 보장됩니까? (0) | 2020.12.09 |