jcconf 2015 workshop 動手玩 java 專案建置工具
Post on 07-Jan-2017
2.122 Views
Preview:
TRANSCRIPT
#JCConf
Java
Gradle Docker
JCConf Taiwan 2015 Workshop
Outline• Introduction• Docker Image Installation• Classical Geb Testing• Geb Test with Dockerize Browser• Gradle Build and Geb Test with Docker
#JCConf
Introduction
PackageLibrary
ApplicationServer
e2e test
auto test success
local debug
test case success success
remote debug
test failed
test failed test failed
#JCConf
Docker Image Installation
docker load• docker load --input ${ }/jcconf_main.tar• docker load --input ${ }/jcconf_client.tar•• docker images• trunk/groovy_gradle• vvoyer/docker-selenium-firefox-chrome
#JCConf
Let’s Start!
#JCConf
Classical Geb Testing
Browser with WebDriver
control
test resultsJava Gradle Geb
••
#JCConf
Demo Repository
GebConfig1. firefox {2. driver = {3. DesiredCapabilities capabilities = DesiredCapabilities.firefox()4. def host = System.env.JCCONF_CLIENT_PORT_4444_TCP_ADDR ?: 'localhost'5. def port = System.env.JCCONF_CLIENT_PORT_4444_TCP_PORT ?: '4444'6. 7. if (host == 'localhost') {8. new FirefoxDriver()9. }10. else {11. URL url = new URL("http://$host:$port/wd/hub")12. new RemoteWebDriver(url, capabilities)13. }14. }15.}16.
src/test/resources/GebConfig.groovy
Target
••• Google Chrome• Firefox
#JCConf
#JCConf
Geb Web Testingwithout Docker
#JCConf
Run Gradle
./gradlew firefoxTest
./gradlew chromeTest
Get Source Code
https://github.com/TrunkWorkshop/jcconf-2015-java-docker
git clone https://github.com/TrunkWorkshop/jcconf-2015-java-docker.git
Testing with Jenkins CI• daily build• code committed• pull request• before staging• before release• trigger manually
Jenkins CI with Real Browser ?• PhantomJS(headless) is not real
??HOW-TO
#JCConf
Geb Test with
Dockerize Browser
browser
test case
control
result
VNC
#JCConf
docker browser
docker-compose up client
#JCConf
View Docker Inside
vnc://DOCKER_HOST:5999
password: secret
• Jenkins CI Test Failed• CI
••
#JCConf
export JCCONF_CLIENT_PORT_4444_TCP_ADDR=DOCKER_HOST
export JCCONF_CLIENT_PORT_4444_TCP_PORT=4444
GebConfig1. firefox {2. driver = {3. DesiredCapabilities capabilities = DesiredCapabilities.firefox()4. def host = System.env.JCCONF_CLIENT_PORT_4444_TCP_ADDR ?: 'localhost'5. def port = System.env.JCCONF_CLIENT_PORT_4444_TCP_PORT ?: '4444'6. 7. if (host == 'localhost') {8. new FirefoxDriver()9. }10. else {11. URL url = new URL("http://$host:$port/wd/hub")12. new RemoteWebDriver(url, capabilities)13. }14. }15.}16.
src/test/resources/GebConfig.groovy
#JCConf
local test + docker browser
gradle remoteFirefoxTest
#JCConf
vnc://DOCKER_HOST:5999
password: secret
#JCConf
Gradle Build and Geb Test with
Docker
client env
project env
browser test case
control
result
VNC JAVAgradle
• CI ••• migrate
#JCConf
docker-compose up main
#JCConf
vnc://dockerhost:5999password: secret
#JCConf
docker-compose
main: container_name: jcconf_main image: trunk/groovy_gradle command: "/bin/bash -l -c 'gradle firefoxTest'" links: - client volumes: - ./:/jcconf_main working_dir: /jcconf_main
client: container_name: jcconf_client image: vvoyer/docker-selenium-firefox-chrome ports: - "4444:4444" - "5999:5999"
Jenkins with Docker
docker-compose up main
top related