* Who Am I? * State of the Room? * CF API * Ways to test your API? * Overview of Testing Tools * Using Testing in your Workflow * Installing Jasmine *

Slides:



Advertisements
Similar presentations
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
Advertisements

T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
GruntJS The JavaScript Task Runner. What is Grunt? A build tool for JavaScript Uses Node to run A Gruntfile is actually just a JavaScript file Therefore,
March 12 & 13, 2007 Mark Drew Reloaded.
With Mocha and Karma Telerik Academy Telerik Software Academy.
Introduction CIS 136 Building Mobile Apps 1. What did we do Software review 2.
* Who Am I? * State of the Room? * Ways to test Javascript? * Different Testing Environments? * Overview of Testing Tools * Using Testing in your Workflow.
® Emerging Internet Technologies © Copyright 2007 IBM Corp. ; made available under the EPL v1.0 AJAX Toolkit Framework Robert Goodman
How to make it work? Doncho Minkov Telerik Academy academy.telerik.com Technical Trainer
SEEM4570: XAMPP, Eclipse, Summary of Html Kangfei Zhao Room 711,ERB
Getting started with Eclipse By Alexander Butyaev.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Cosc 5/4730 Sign, convert, and install Android files on Blackberry Playbook.
JQuery CS 268. What is jQuery? From their web site:
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
CS490 Web Design, AJAX, JQuery
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Zero to Testing in JavaScript Basics of testing in JS.
JavaScript & jQuery the missing manual Chapter 11
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
LPHI ITG Emergency Preparedness Information Sessions & Training.
CS Tutorial 1 Getting Started with Visual Studio 2012 (Visual Studio 2010 are no longer available on MSDNAA, please choose Visual Studio 2012 which.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Unit and Functional Testing Your Flex Applications Mike Nimer Dir. Of Engineering nomee.com.
Jasmine Testing Framework. What’s Jasmine For? Framework for Test Driven Development Designed around acceptance testing Works in any environment (with.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Hélène kay Webdiva Consultants Dreamweaver Week 8 hélène kay hélène kay.
An Introduction to Front-end Web Development Tom Perkins.
A TEST FRAMEWORK USING PROTRACTOR, CUCUMBER & CUCUMBER SANDWICH
Topic Java EE installation (Eclipse, glassfish, etc.) Eclipse configuration for EE Creating a Java Web Dynamic Project Creating your first servlet.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
Chapter 10 Chapter 10: Managing the Distributed File System, Disk Quotas, and Software Installation.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Esri UC 2014 | Technical Workshop | Creating Geoprocessing Services Kevin Hibma.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Introduction Selenium IDE is a Firefox extension that allows you to record, edit, and debug tests for HTML Easy record and playback Intelligent field selection.
1 Presentation Title Test-driven development (TDD) Overview David Wu.
Surya Bahadur Kathayat Outline  Ramses  Installing Ramses  Ramses Perspective (Views and Editors)  Importing/Exporting Example.
ICM – API Server & Forms Gary Ratcliffe.
Unit Testing in JavaScript with Mocha, Chai and Karma SoftUni Team Technical Trainers Software University
JavaScript Unit Test by MinHo Kim (Dexter Developer Guide)
Unit Testing with FlexUnit
Selenium server By, Kartikeya Rastogi Mayur Sapre Mosheca. R
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JQUERY AND AJAX
Testing Unit Testing In Evergreen Kevin Beswick Laurentian University / Project Conifer.
XP New Perspectives on Creating Web Pages With Word Tutorial 1 1 Creating Web Pages With Word Tutorial 1.
Online Conference June 17 th and 18 th Modern SharePoint Development using Visual Studio Code.
I18n - DateTime ASP.NET MVC. I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)
Downloading and Installing GRASP-AF Workshop Ian Robson Information Analyst, North of England Cardiovascular Network.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
UNIT TESTING IN ANGULARJS Dhananjay
Using React, Drupal and Google Chrome to build an interactive kiosk + + =
Lean With MEAN.
JavaScript, Sixth Edition
Development Environment
Test-driven development
Unit Testing with Mocha
Data Virtualization Tutorial… CORS and CIS
SharePoint Bruger Gruppe (SPBG) SharePoint Framework Introduction
Top 5 Front End Development Tools. 1. Sublime Text Sublime Text may be a super quick and have packed text and development editor. If you're about to be.
Skill Based Assessment
React Revived Web Driver IO for Testers
Testing REST IPA using POSTMAN
Microsoft Ignite NZ October 2016 SKYCITY, Auckland.
Test-driven development (TDD)
Lightning Component Testing with Jasmine Jasmine is a behaviour-driven development framework - that is used for the purpose of testing Javascript code.
Cordova & Cordova Plugin Installation and Management
Agile testing for web API with Postman
Lecture 12: The Fetch Api and AJAx
Presentation transcript:

* Who Am I? * State of the Room? * CF API * Ways to test your API? * Overview of Testing Tools * Using Testing in your Workflow * Installing Jasmine * Installing Testbox * Live Demo

* Gavin Pickin – developing Web Apps since late 90s * New Addition to Ortus Solutions * ContentBox Evangelist * What else do you need to know? * Blog - * Twitter – * Github - * Lets get on with the show.

* A few questions for you guys * If you have arms, use them.

* Most CF Apps are moving towards providing an API for multiple consumers * CF has many REST API Solutions and even more with CF 12 coming soon * Built in CF * Built in Railo/Lucee * Coldbox API * Taffy

* Click around in the browser yourself * Setup Selenium / Web Driver to click around for you * Structured Programmatic Tests

* Black/White Box * Unit Testing * Integration Testing * Functional Tests * System Tests * End to End Tests * Sanity Testing * Regression Test * Acceptance Tests * Load Testing * Stress Test * Performance Tests * Usability Tests * + More

* Integration Tests several of the pieces together * Most of the types of tests are variations of an Integration Test * Can include mocks but can full end to end tests including DB / APIs

“unit testing is a software verification and validation method in which a programmer tests if individual units of source code are fit for use. A unit is the smallest testable part of an application” - wikipedia

* Can improve code quality -> quick error discovery * Code confidence via immediate verification * Can expose high coupling * Will encourage refactoring to produce > testable code * Remember: Testing is all about behavior and expectations

* TDD = Test Driven Development * Write Tests * Run them and they Fail * Write Functions to Fulfill the Tests * Tests should pass * Refactor in confidence * Test focus on Functionality

* BDD = Behavior Driven Development Actually similar to TDD except: * Focuses on Behavior and Specifications * Specs (tests) are fluent and readable * Readability makes them great for all levels of testing in the organization * Hard to find TDD examples in JS that are not using BDD describe and it blocks

Test( ‘ address must not be blank’, function(){ notEqual( , “”, "failed"); });

Describe( ‘ Address’, function(){ It(‘should not be blank’, function(){ expect( ).not.toBe(“”); });

expect(true).toBe(true);

expect(true).not.toBe(true);

expect(true).toBe(true); expect(a).not.toBe(null); expect(a).toEqual(12); expect(message).toMatch(/bar/); expect(message).toMatch("bar"); expect(message).not.toMatch(/quux/); expect(a.foo).toBeDefined(); expect(a.bar).not.toBeDefined();

NodeJS - CLI In the Browser

* MxUnit was the standard * TestBox is the new standard * Other options

TestBox is a next generation testing framework for ColdFusion (CFML) that is based on BDD (Behavior Driven Development) for providing a clean obvious syntax for writing tests. It contains not only a testing framework, runner, assertions and expectations library but also ships with MockBox, A Mocking & Stubbing Framework,. It also supports xUnit style of testing and MXUnit compatibilities.

function testHelloWorld(){ $assert.includes( helloWorld(), ”world" ); }

describe("Hello world function", function() { it(”contains the word world", function() { expect(helloWorld()).toContain("world"); });

feature( "Box Size", function(){ describe( "In order to know what size box I need As a distribution manager I want to know the volume of the box", function(){ scenario( "Get box volume", function(){ given( "I have entered a width of 20 And a height of 30 And a depth of 40", function(){ when( "I run the calculation", function(){ then( "the result should be 24000", function(){ // call the method with the arguments and test the outcome expect( myObject.myFunction(20,30,40) ).toBe( ); });

* There are a few choices

* Jasmine, Mocha and QUnit

* Jasmine comes ready to go out of the box * Fluent Syntax – BDD Style * Includes lots of matchers * Has spies included * Very popular, lots of support * Angular uses Jasmine with Karma (CLI) * Headless running and plays well with CI servers

* Async testing in 1.3 can be a headache * Async testing in 2.0 is hard to find blog posts on (I need to write one) * Expects *spec.js suffix for test files * This can be modified depending on how you are running the tests

describe("Hello world function", function() { it(”contains the word world", function() { expect(helloWorld()).toContain("world"); });

* Simple Setup * Simple Async testing * Works great with other Assertion libraries like Chai ( not included ) * Solid Support with CI Servers, with Plugins for others * Opinion says Mocha blazing the trail for new features

* Requires other Libraries for key features * No Assertion Library included * No Mocking / Spied included * Need to create the runner manually * Newer to the game so not as popular or supported as others but gaining traction.

var expect = require('chai').expect; describe(’Hello World Function', function(){ it('should contain the word world', function(){ expect(helloWorld()).to.contain(’world'); })

* The oldest of the main testing frameworks * Is popular due to use in jQuery and age * Ember’s default Unit testing Framework

* Development slowed down since 2013 (but still under development) * Syntax – No BDD style * Assertion libraries – limited matchers

QUnit.test( "ok test", function( assert ) { assert.ok( true, "true succeeds" ); assert.ok( "non-empty", "non-empty string succeeds" ); assert.ok( false, "false fails" ); assert.ok( 0, "0 fails" ); assert.ok( NaN, "NaN fails" ); assert.ok( "", "empty string fails" ); assert.ok( null, "null fails" ); assert.ok( undefined, "undefined fails" ); });

Photo Credit – Kombination

* Things to refactor to make your code testable * Code should not be one big chunk of Javascript in onReady() * Deep nested callbacks & Anon functions cannot easily be singled out and tested * Remove Tight Coupling – DOM access for example

* Lets look at some code * This isn’t BEST PRACTICE, its BETTER PRACTICE than you were doing * Its not really refactoring if you don’t have tests, its “moving code and asking for trouble” Kev McCabe

var personObjLit = { ssn: ’xxxxxxxx', age: '35', name: 'Gavin Pickin', getAge: function(){ return this.age; }, getName: function() { return this.name; } };

var personObjLit2 = function() { ssn = ’xxxxxxx'; age = '35'; name = 'Gavin Pickin’; return { getAge: function(){ return age; }, getName: function() { return name; } };

* Using HTML Test Runners * Keep a Browser open * F5 refresh tests

* Run Jasmine – manual * Run tests at the end of each section of work * Run Grunt-Watch – automatic * Runs Jasmine on every file change * Grunt can run other tasks as well, minification etc

* Browser Views * Eclipse allows you to open files in web view – uses HTML Runner * Run Jasmine / Grunt / Karma in IDE Console * Fairly Easy to setup * See Demo– Sublime Text 2 (if we have time)

* Install / Run Jasmine Standalone for Browser * Install / Run Jasmine with NodeJs * Install / Run Jasmine with Grunt Watch * Install / Run Testbox in Browser * Install / Run Testbox with Grunt Watch * Install / Run Grunt Watch inside Sublime Text 2

Download standalone package from Github (I have 2.1.3) Unzip into your /tests folder Run /tests/SpecRunner.html to see example tests

Jasmine Spec Runner v2.1.3

Assuming you have NodeJs Installed… install Jasmine $ npm install jasmine node_modules/jasmine ├── ├── └──

Once Jasmine is installed in your project $ Jasmine init

Edit Jasmine.json to update Locations for Spec Files and Helper Files { "spec_dir": "spec", "spec_files": [ "**/*[sS]pec.js" ], "helpers": [ "helpers/**/*.js" ] }

$ Jasmine Started F Failures: 1) A suite contains spec with an expectation Message: Expected true to be false. Stack: Error: Expected true to be false. at Object. (/Users/gavinpickin/Dropbox/Apps/testApp/www/spec/test_spec.js:3 :18) 1 spec, 1 failure Finished in seconds

* Jasmine-Node is great for Node * Jasmine Node doesn’t have a headless browser * Hard to test Browser code * So what should I use?

* Install Grunt npm install grunt * Install Grunt – Jasmine npm install grunt-contrib-jasmine * Install Grunt – Watch npm install grunt-contrib-watch * Note: On Mac, I also needed to install Grunt CLI npm install –g grunt-cli

// gruntfile.js - module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('node_modules/grunt/package.json'), jasmine: { all: { src: ['js/*.js' ], options: { //'vendor': ['path/to/vendor/libs/*.js'], 'specs': ['specs/*.js' ], '--web-security': false } },

// gruntfile.js part 2 watch: { js: { files: [ 'js/*.js', 'specs/*.js', ], tasks: ['jasmine:all'] } });

// gruntfile.js part 3 grunt.loadNpmTasks('grunt-contrib-jasmine'); grunt.loadNpmTasks('grunt-contrib-watch'); };

describe("Forgotten Password Form", function() { it("should warn you if the is invalid before making Ajax Call", function() { expect( is InputInvalid('') ).toBe(true); expect( is InputInvalid('dddddddddd') ).toBe(true); expect( ).toBe(true); expect( ).toBe(true); expect( ).toBe(true); expect( ).toBe(false); });

describe("Login Form", function() { it("should set status correct status message with successful Ajax Response", function() { spyOn( window, "setStatusMessage"); processLoginAjaxDone('{"RESULT":"200"}'); expect(setStatusMessage).toHaveBeenCalled(); expect(setStatusMessage).toHaveBeenCalledWith( ‘TARDIS Access Granted - Please wait for the Doctor to take you for a spin'); });

describe("Login API", function() { it("should return a failing Ajax Response", function() { spyOn( window, "processLoginAjaxDone"); loginButtonEventHandlerProcess( 'password'); expect(processLoginAjaxDone).toHaveBeenCalled(); expect(processLoginAjaxDone).toHaveBeenCalledWith( ‘{"RESULT":400}'); expect(processLoginAjaxFail).not.toHaveBeenCalled(); });

describe("Login API", function() { it("should return a failing Ajax Response", function() { spyOn( window, "processLoginAjaxDone"); loginButtonEventHandlerProcess( 'password'); expect(processLoginAjaxDone).toHaveBeenCalled(); expect(processLoginAjaxDone).toHaveBeenCalledWith( ‘{"RESULT":400}'); expect(processLoginAjaxFail).not.toHaveBeenCalled(); });

* You want Unit Tests to test the unit and not it’s dependencies * You want Unit Tests to run quick * You should mock the API in the Ajax call * But we want to test the API * So essentially, we’re writing an integration test.

describe("Login API", function() { beforeEach(function( done ) { spyOn( window, "processLoginAjaxDone").and.callFake( function(){ done(); }); spyOn( window, "processLoginAjaxFail").and.callFake( function(){ done(); }); 'password'); }); it("should return a failing Ajax Response", function() { }); });

describe("Login API", function() { beforeEach(function( done ) { … }); it("should return a failing Ajax Response", function() { expect(processLoginAjaxDone).toHaveBeenCalled(); expect(processLoginAjaxDone).toHaveBeenCalledWith( '{"RESULT":400}'); expect(processLoginAjaxFail).not.toHaveBeenCalled(); });

* Install Testbox – Thanks to Commandbox * box install testbox * Decide how you want to run Testbox

*

// tests/specs/CFCTest.cfc component extends="testbox.system.BaseSpec" { function run() { it( "will error with incorrect login", function(){ var oTest = new cfcs.userServiceRemote(); expect( oTest.login( 'topsecret').result ).toBe('400'); }); }

// tests/specs/APITest.cfc component extends="testbox.system.BaseSpec" { function run() { describe("userService API Login", function(){ it( "will error with incorrect login", function(){ var = var password = "topsecret”; var result = ""; http url=" d=login& =# #&password=#password#" result="result”; expect( DeserializeJSON(result.filecontent).result ).toBe('400'); }); }

* Install Testbox Runner – Thanks Sean Coyne * npm install testbox-runner * Install Grunt Shell * npm install grunt-shell * Add Grunt Configuration

* Install Testbox Runner – Thanks Sean Coyne * npm install testbox-runner * Install Grunt Shell * npm install grunt-shell * Add Grunt Configuration

module.exports = function (grunt) { grunt.loadNpmTasks('grunt-shell'); grunt.initConfig({ … }) }

Watch: { … cfml: { files: [ "cfcs/*.cfc"], tasks: [ "testbox" ] }

shell: { testbox: { command: "./node_modules/testbox- runner/index.js --colors --runner unner.cfm --directory /tests/specs --recurse true” }

grunt.registerTask("testbox", [ "shell:testbox" ]); grunt.loadNpmTasks('grunt-contrib-jasmine'); grunt.loadNpmTasks('grunt-contrib-watch');

js: { files: [ 'js/*.js', 'specs/*.js', "cfcs/*.cfc” ], tasks: ['jasmine:all'] },

Jasmine 676d23c5 Jasmine + Testbox b63c7e7

* Testbox has several runners, you have seen the HTML one, this Runner uses the JSON runner and then formats it. * ner.cfm?reporter=JSON&directory=%2Ftests%2Fspec s&recurse=true ner.cfm?reporter=JSON&directory=%2Ftests%2Fspec s&recurse=true

* Install PackageControl into Sublime Text * Install Grunt from PackageControl * * Update Grunt Sublime Settings for paths { "exec_args": { "path": "/bin:/usr/bin:/usr/local/bin” } } * Then Command Shift P – grunt

* Any questions? * Interesting Link: javascript-testing-in-10-minutes-2a b

FREE ONLINE