Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Into The Box 2018 Automate Your Test

41 views

Published on

Lonnie Ramirez

Published in: Software
  • Be the first to comment

  • Be the first to like this

Into The Box 2018 Automate Your Test

  1. 1. 5/10/18, 11(03 PM Page 1 of 15http://localhost:8000/?print-pdf AUTOMATE YOUR TESTS BY LONNIE RAMIREZ REPO: HTTPS://GITHUB.COM/LRAMIREZ925/JE NKINSCFPRESENTATION
  2. 2. 5/10/18, 11(03 PM Page 2 of 15http://localhost:8000/?print-pdf Code, without tests, is not clean. No matter how elegant it is, no matter how readable and accessible, if it hath not tests, it be unclean. --Robert C. Martin, Clean Code: A Handbook of Agile So!ware Cra!smanship
  3. 3. 5/10/18, 11(03 PM Page 3 of 15http://localhost:8000/?print-pdf WHO AM I From Johnstown, PA (Yes we flooded ourselves 3 times). Graduated from UPJ and currently attending Syracuse University's Online Masters Program Avid adventurer into Scifi and Anime conventions. I constantly break everything so I am always looking for new ways to find where I broke it. Twitter: epicureannerd Email: epicureannerd@gmail.com
  4. 4. 5/10/18, 11(03 PM Page 4 of 15http://localhost:8000/?print-pdf
  5. 5. 5/10/18, 11(03 PM Page 5 of 15http://localhost:8000/?print-pdf SOME USEFUL COMMANDS 1. install testbox - This installs testbox to your app adding the entry to the box. 1. cfconfig import - Installs your config.... depending on your docker setup may not 1. server start port=8080 - runs your server using default server.json and uses this port.
  6. 6. 5/10/18, 11(03 PM Page 6 of 15http://localhost:8000/?print-pdf SOME USEFUL COMMANDS 1. testbox run Runs the default url set in the box.json parameters runner=" " The url to your runner. This is why we set the port ourselves. reporter="JUnit" Reporter type. Using JUnit because jenkins can use it by default directory="tests.bundles" Directory where your rests are. outputFile="./junitResults.xml"' File to output the test results to be archived. http://localhost:8080/tests/runner.cfm
  7. 7. 5/10/18, 11(03 PM Page 7 of 15http://localhost:8000/?print-pdf
  8. 8. 5/10/18, 11(03 PM Page 8 of 15http://localhost:8000/?print-pdf JENKINS Jenkins is an open source automation server written in Java. Jenkins helps to automate the non-human part of so!ware development process, with continuous integration and facilitating technical aspects of continuous delivery. --Wikipedia
  9. 9. 5/10/18, 11(03 PM Page 9 of 15http://localhost:8000/?print-pdf JENKINS --https://jenkins.io/doc/book/installing/ docker run -u root --rm -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
  10. 10. 5/10/18, 11(03 PM Page 10 of 15http://localhost:8000/?print-pdf JENKINS PIPELINE FILE File name is JenkinsFile though can be changed. Can be written in Declarative or Scripted, both are forms of groovy Declaritive is easier and stricter Scripted is more flexible and powerful If you can run via command line then you can run it in jenkins. If you can't run via commandline get CommandBox
  11. 11. 5/10/18, 11(03 PM Page 11 of 15http://localhost:8000/?print-pdf WHY USE A PIPELINE FILE Steps for testing are in your repo. If one branch adds a new testing method or step it won't break other branches. Can work with almost any work flow. For more advanced features you can program in groovy.
  12. 12. 5/10/18, 11(03 PM Page 12 of 15http://localhost:8000/?print-pdf BASIC CODE. pipeline { // Top level required. agent { // Specifies where the the pipeline will execute. docker { // Execute the pipeline within a docker image image 'ortussolutions/commandbox' // Image for docker args '-u=root' } } stages { // Bulk of the work happens here. Is made up of multiple stage children. Does them in order stage('Build') { //Different steps in the stages section steps { //Here is the actions that occur in the stage echo 'In Build Script. ' //simply output the string sh 'ls' // Perform command line actions. sh 'box server start port=8080' sh 'box cfconfig import myConfig.json' sh 'box cfconfig import testConfig.json' sh 'box install' sh 'box server restart' } } stage('Unit Tests') { //Testing stage. This does not run if previous stages have failed. steps { echo 'Running Unit Tests' sh 'box testbox run runner="http://localhost:8080/tests/runner.cfm" reporter="JUnit" direct sh 'ls' junit 'junitResults.xml' } } stage('Deploy') { steps { echo 'Deploying' } } } post { // This always occurs even if something failed. always { archiveArtifacts "src/**/*"
  13. 13. 5/10/18, 11(03 PM Page 13 of 15http://localhost:8000/?print-pdf CFLINT EXAMPLE CODE. pipeline { agent { docker { image 'ortussolutions/commandbox' args '-u=root' } } stages { stage('Build') { steps { echo 'In Build Script. ' sh 'box install commandbox-cflint' sh 'box server start port=8080' sh 'box cfconfig import myConfig.json' sh 'box cfconfig import testConfig.json' sh 'box install' sh 'box server restart' } } stage('Unit Tests') { parallel { stage('Unit Tests') { steps { echo 'Running Unit Tests' sh 'box testbox run runner="http://localhost:8080/tests/runner.cfm" reporte sh 'ls' junit 'junitResults.xml' } } stage('runCFLint') { steps { sh 'box cflint exitOnError=false --html pattern="**/src/**|**/tests/"' archiveArtifacts 'cflint-results.html' } }
  14. 14. 5/10/18, 11(03 PM Page 14 of 15http://localhost:8000/?print-pdf CACHE ARTIFACTS EXAMPLE CODE. pipeline { agent { docker { image 'ortussolutions/commandbox' args '''-u=root -v commandBoxArtifacts:/root/.CommandBox/artifacts''' } } stages { stage('Build') { steps { echo 'In Build Script. ' sh 'ls' sh 'box server start port=8080' sh 'box cfconfig import myConfig.json' sh 'box cfconfig import testConfig.json' sh 'box install' sh 'box server restart' } } stage('Unit Tests') { steps { echo 'Running Unit Tests' sh 'box testbox run runner="http://localhost:8080/tests/runner.cfm" reporter="JUnit" direct sh 'ls' junit 'junitResults.xml' } } stage('Deploy') { steps {
  15. 15. 5/10/18, 11(03 PM Page 15 of 15http://localhost:8000/?print-pdf IT IS THAT SIMPLE Twitter: epicureannerd Email: epicureannerd@gmail.com

×