north virginia - coldfusion user group presentation - july 19th 2017
TRANSCRIPT
![Page 1: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/1.jpg)
TestBoxCFUG Meetup
July 19th
![Page 2: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/2.jpg)
Who am I
Gavin Pickin – developing Web Apps since late 90s
● New Addition to Ortus Solutions● ContentBox Evangelist
What else do you need to know?● Blog - http://www.gpickin.com● Twitter – http://twitter.com/gpickin● Github - https://github.com/gpickin
Let’s get on with the show.
![Page 3: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/3.jpg)
So who is already using testing?
![Page 4: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/4.jpg)
Trick Question - You are all testing your apps.
● Most people look like this guyClicking around in the browser yourself
● Setup Selenium / Web Driver to click around for you
● Structured Programmatic Tests
![Page 5: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/5.jpg)
Bugs Hurt You
![Page 6: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/6.jpg)
Bugs Hurt
•Bugs hurt – the later in the process, the harder to
fix.
•Test Early and Often
–Find them before they rot your foundation
•Testable Code is Maintainable Code
![Page 7: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/7.jpg)
Types of Testing
● 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
![Page 8: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/8.jpg)
Important Testing Types
•Unit Testing
–Test behavior of individual objects
•Integration Testing
–Test Entire Application from Top Down
•UI verification testing
Verification via HTML/Visual elements
![Page 9: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/9.jpg)
Important Testing Tools
•TestBox (Run BDD and MXUnit style)
•IDE - CF Builder / Eclipse
•Mocking Framework
•ANT
•Jenkins, Bamboo, Teamcity, other Cis
•Selenium
•Jmeter or Webstress Tool, Apache AB
![Page 10: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/10.jpg)
What is TestBox?
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.
More info: https://www.ortussolutions.com/products/testbox
![Page 11: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/11.jpg)
Integration Tests
● 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
![Page 12: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/12.jpg)
What is Unit Testing
“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
![Page 13: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/13.jpg)
Unit Testing
•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
![Page 14: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/14.jpg)
Style of Testing - TDD vs BDD
● 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
![Page 15: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/15.jpg)
Style of Testing - TDD vs BDD
● 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
![Page 16: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/16.jpg)
TDD Example
Test( ‘Email address must not be blank’, function(){
notEqual(email, “”, "failed");
});
![Page 17: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/17.jpg)
BDD Example
Describe( ‘Email Address’, function(){
It(‘should not be blank’, function(){
expect(email).not.toBe(“”);
});
});
![Page 18: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/18.jpg)
BDD Matchers
expect(true).toBe(true);
expect(true).toBe(true);
expect(true).toBe(true);
expect(true).toBe(true);
![Page 19: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/19.jpg)
BDD Matchers
expect(true).not.toBe(true);
expect(true).not.toBe(true);
expect(true).not.toBe(true);
expect(true).not.toBe(true);
expect(true).not.toBe(true);
![Page 20: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/20.jpg)
Matcher Examples
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();
![Page 21: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/21.jpg)
BDD Example
describe("Hello world function", function() {
it(”contains the word world", function() {
expect(helloWorld()).toContain("world");
});});
![Page 22: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/22.jpg)
New BDD Examplefeature( "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( 24000 );
});
});
});
});
});
});
![Page 23: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/23.jpg)
Installing Testbox
Install Testbox – Thanks to Commandbox - this is easy.
# box install testbox
Next, we need to decide how you want to run Testbox
![Page 24: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/24.jpg)
Create a Runner.cfm File to Run your tests<cfsetting showDebugOutput="false">
<!--- Executes all tests in the 'specs' folder with simple reporter by default --->
<cfparam name="url.reporter" default="simple">
<cfparam name="url.directory" default="tests.specs">
<cfparam name="url.recurse" default="true" type="boolean">
<cfparam name="url.bundles" default="">
<cfparam name="url.labels" default="">
<!--- Include the TestBox HTML Runner --->
<cfinclude template="/testbox/system/runners/HTMLRunner.cfm" >
![Page 25: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/25.jpg)
Create a test suite// 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( '[email protected]', 'topsecret').result ).toBe('400');
});
}
}
![Page 26: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/26.jpg)
Create 2nd Test Suite// tests/specs/APITest.cfccomponent extends="testbox.system.BaseSpec" { function run() { describe("userService API Login", function(){ it( "will error with incorrect login", function(){ var email = "[email protected]"; var password = "topsecret”; var result = ""; http url="http://www.testableapi.local.com:8504/cfcs/userServiceRemote.cfc?method=login&email=#email#&password=#password#" result="result”;
expect( DeserializeJSON(result.filecontent).result ).toBe('400'); }); });
}}
![Page 27: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/27.jpg)
Run tests in Browser with Runner
![Page 28: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/28.jpg)
Run tests with Grunt
● Install Testbox Runner – Thanks Sean Coyne
# npm install testbox-runner
● Install Grunt Shell
# npm install grunt-shell
Then, we need to add Grunt Configuration
![Page 29: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/29.jpg)
Add Grunt Config - 1
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({ … })
}
![Page 30: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/30.jpg)
Add Grunt Config - 2
Watch: {
…
cfml: {
files: [ "cfcs/*.cfc"],
tasks: [ "testbox" ]
}}
![Page 31: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/31.jpg)
Add Grunt Config - 3
shell: {
testbox: {
command: "./node_modules/testbox-runner/index.js --colors --runner http://www.testableapi.local.com:8504/tests/runner.cfm --directory /tests/specs --recurse true”
}
}
![Page 32: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/32.jpg)
Add Grunt Config - 4
grunt.registerTask("testbox", [ "shell:testbox" ]);
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-watch');
![Page 33: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/33.jpg)
Grunt Config Gists
Jasmine + Testbox
https://gist.github.com/gpickin/9fc82df3667eeb63c7e7
![Page 34: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/34.jpg)
TestBox output with Grunt
![Page 35: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/35.jpg)
TestBox JSON output
Testbox has several runners, you have seen the HTML one, this Runner uses the JSON runner and then formats it.
http://www.testableapi.local.com:8504/tests/runner.cfm?reporter=JSON&directory=%2Ftests%2Fspecs&recurse=true
![Page 36: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/36.jpg)
Running TestBox in Sublime 2
Install PackageControl into Sublime Text
Install Grunt from PackageControl
https://packagecontrol.io/packages/Grunt
Update Grunt Sublime Settings for paths{
"exec_args": { "path": "/bin:/usr/bin:/usr/local/bin” }
}
Then Command Shift P – grunt
![Page 37: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/37.jpg)
TestBox Output in Sublime 2
![Page 38: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/38.jpg)
Run TestBox with CommandBox
Run the tests in the box.json file.
# testbox run
Watch the folders and run tests on change
# testbox watch
More info on TestBox usage from CommandBox: https://www.ortussolutions.com/blog/using-testbox-watch-to-automate-your-testing-suite
![Page 39: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/39.jpg)
More Testing - Mocking with MockBox
"A mock object is an object that takes the place of
a ‘real’ object in such a way that makes testing
easier and more meaningful, or in some cases,
possible at all"
by Scott Bain - Emergent Design
![Page 40: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/40.jpg)
More Testing - IntegratedStart using an easy, fluent API for your integration tests!
More Info: https://github.com/elpete/integrated
Api - https://elpete.github.io/integrated/
![Page 41: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/41.jpg)
Some real life exampleshttps://github.com/framework-one/fw1/tree/develop/tests maybe?
https://github.com/Ortus-Solutions/TestBox/tree/development/tests
https://github.com/foundeo/cfdocs/tree/master/tests
https://github.com/foundeo/cfmlparser/tree/master/tests/tests
https://github.com/foundeo/toscript/tree/master/tests
https://github.com/foundeo/bolthttp/tree/master/test
https://github.com/foundeo/cfml-security/tree/master/tests/tests/secureupload
![Page 42: North Virginia - ColdFusion User Group Presentation - July 19th 2017](https://reader031.vdocuments.net/reader031/viewer/2022030317/5a64fe3b7f8b9af3398b4bdd/html5/thumbnails/42.jpg)
Some real life examples cont.https://github.com/ryanguill/emit/tree/master/tests
https://github.com/ryanguill/cfmlBase62/tree/master/tests
https://gitlab.com/ryanguill/FPcfc/tree/master/tests
https://gitlab.com/ryanguill/template-cfc/tree/master/tests
https://github.com/MotorsportReg/sidecar/tree/master/tests/basic
https://github.com/MotorsportReg/sidecar/tree/master/tests/basic