SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
Testacular
Javascript Testing with
Node.js, Testacular & Jasmine
"Man, I just love unit tests, I've just been able to make
a bunch of changes to the way something works, and
then was able to confirm I hadn't broken anything by
running the test over it again..."
1. Unit Tests allow you to make big changes to code quickly. You know it works now because you've
run the tests, when you make the changes you need to make, you need to get the tests working
again. This saves hours.
2. TDD helps you to realise when to stop coding. Your tests give you confidence that you've done
enough for now and can stop tweaking and move on to the next thing.
3. The tests and the code work together to achieve better code. Your code could be bad / buggy.
Your TEST could be bad / buggy. In TDD you are banking on the chances of BOTH being bad /
buggy being low. Often it's the test that needs fixing but that's still a good outcome.
4. TDD helps with coding constipation. When faced with a large and daunting piece of work ahead
writing the tests will get you moving quickly.
5. Unit Tests help you really understand the design of the code you are working on. Instead of
writing code to do something, you are starting by outlining all the conditions you are subjecting
the code to and what outputs you'd expect from that.
Why Unit Test Javascript? part 1
6. Unit Tests give you instant visual feedback, we all like the feeling of all those green lights when
we've done. It's very satisfying. It's also much easier to pick up where you left off after an
interruption because you can see where you got to - that next red light that needs fixing.
7. Contrary to popular belief unit testing does not mean writing twice as much code, or coding
slower. It's faster and more robust than coding without tests once you've got the hang of it. Test
code itself is usually relatively trivial and doesn't add a big overhead to what you're doing. This is
one you'll only believe when you're doing it :)
8. I think it was Fowler who said: "Imperfect tests, run frequently, are much better than perfect
tests that are never written at all".
9. Good unit tests can help document and define what something is supposed to do
10. Unit tests help with code re-use. Migrate both your code AND your tests to your new project.
Tweak the code till the tests run again.
Why Unit Test Javascript? part 2
● Sanity testing - Are the expected functions and
classes available?
● Regression testing - Is that bug squashed, and will
never appear again?
● Functional testing - Given x, do y.
● Specification tests - I don't have real world data,
but assuming I get data in this format...
● Edge-case testing - This expects a Number, but if
someone gives it a String...
Why do we use Unit Testing?
Running Tests
● Developed + Open Sourced by Google.
● Node.js === Native Javascript, using the V8 framework.
● Works with any* browser.
● Works without any IDE.
● Integration with CI servers.
● Stable.
● Fast.
● Line, branch, statement & function coverage test
data.
● Jasmine, Mocha & AngularJS testing frameworks.
Why Testacular?
● It can't evaluate code coverage in any more
depth than line coverage.
● It's Java based.
● Slower than Testacular.
Why not JSTestDriver?
● Configuration file specifies:
○ Input files (source code and test files)
○ Browsers to test with
○ Excluded files, coverage tests, ports, run mode, output format, base path, etc...
● Command line execution:
> testacular start
How does it work?
Let's see that in action...
Writing Tests
Sanity testing
/js/rio.js
var RIO = {
init: initialise,
model: new RIOModel(),
data: new RIOData(),
controller: new RIOController()
};
/tests/rio.tests.js
describe("RIO Object", function() {
it("has the expected API", function() {
expect(RIO).toBeDefined();
expect(typeof(RIO)).toBe("object");
expect(typeof(RIO.init)).toBe("function");
expect(typeof(RIO.model)).toBe("object");
expect(typeof(RIO.data)).toBe("object");
expect(typeof(RIO.controller)).toBe("object");
});
});
Regression testing
/tests/regression.test.js
describe("Defect DE248 Regression test", function() {
beforeEach(function() {
readFixtures('simple-fixture.html');
var options = {
containerElement: $('div.sample-1'),
dataProvider: Standalone.DataProvider,
pathToAssets: "base/mockdata/mfl/"
};
var activeTextInstance = new ActiveText(options);
});
it("stops the iframes overlapping", function() {
var iframeWidth = $('div.sample-1').find('div.iframe').width();
var dpsWidth = $('div.sample-1').find('div.reader').width();
expect(iframeWidth < dpsWidth).toBeTruthy();
expect(iframeWidth).toBeCloseTo(dpsWidth / 2);
});
});
Functional testing
/tests/utils.tests.js
describe("Functional tests for the utils class", function() {
it('checks the output of getCorrectPathToAssetsFromHTMLPageAt', function()
{
var instance = new ActiveText.Loader({
pathToAssets: "mockdata/exploringscience/"
});
var output = instance.test.getCorrectPathToAssetsFromHTMLPageAt(
"images/page0001Exploring_Science_AT_v1.pdf.png");
expect(output).toBe("mockdata/exploringscience/images/");
...
});
});
Specification testing
/tests/specification.test.js
$.ajaxSetup({
async: false
});
$.mockjax({
url: 'mockdata/sockosaurus/META-INF/container.xml',
responseType: "xml",
responseText: '<?xml version="1.0" encoding="UTF-8"?><container version="
1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"
><rootfiles><rootfile full-path="OPS/book.opf" media-type="application/oebps-
package+xml"/></rootfiles></container>'
});
describe("Data Loader test", function() {
it("loads data", function() {
activeTextInstance.loader.loadData();
expect(activeTextInstance.data.getPath()).toBe("OPS/book.opf");
});
});
Edge-case testing
/tests/edgecase.tests.js
describe("Navigation tests", function() {
it("tests the edge cases", function() {
activeTextInstance.navigation.gotoPage(5);
expect(activeTextInstance.model.getCurrentPageNumber()).toBe(5);
activeTextInstance.navigation.gotoPage(12);
expect(activeTextInstance.model.getCurrentPageNumber()).toBe(12);
activeTextInstance.navigation.gotoPage(-500);
expect(activeTextInstance.model.getCurrentPageNumber()).toBe(0);
activeTextInstance.navigation.gotoPage(500);
expect(activeTextInstance.model.getCurrentPageNumber()).toBe(26);
});
});
● describe(name, function)
● it(name, function)
● beforeEach(function) / afterEach(function)
● expect(condition).toBe(value);
● expect(condition).not.toBe(value);
● .toEqual() / .toBeTruthy() / .toBeFalsy()
● waitsFor(function) / runs(function)
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
expect(true).not.toBe(false);
});
});
Writing tests in Jasmine
Setup time
Python 2.7
node.js + npm
testacular
Growl Notifications
PhantomJS
http://www.python.org/download/releases/
http://nodejs.org/
http://testacular.github.com/0.6.0/intro/
installation.html
http://www.growlforwindows.com/gfw/
http://phantomjs.org/
Installing Testacular + Jasmine
Optional Extras
> testacular init
Time to write some tests...
Time to write some code...
How many tests do you need?
// Testacular configuration
// base path, that will be used to resolve files and exclude
basePath = '';
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'js/**/*.js',
'js-tests/**/*.js'
];
// list of files to exclude
exclude = [];
preprocessors = {
'js/**/*.js' : 'coverage'
};
coverageReporter = {
type: 'lcov',
dir: 'coverage/'
};
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress', 'coverage'];
// web server port
port = 7654;
Testacular configuration file + coverage
// cli runner port
runnerPort = 9100;
// enable / disable colors in the output (reporters and logs)
colors = true;
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN ||
LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;
// enable / disable watching file and executing tests whenever any
file changes
autoWatch = true;
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['PhantomJS'];
// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;
That's all folks
@psyked_james / aka James Ford

Mais conteúdo relacionado

Mais procurados

Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)vilniusjug
 
GeeCON 2012 hurdle run through ejb testing
GeeCON 2012 hurdle run through ejb testingGeeCON 2012 hurdle run through ejb testing
GeeCON 2012 hurdle run through ejb testingJakub Marchwicki
 
iOS Unit Testing
iOS Unit TestingiOS Unit Testing
iOS Unit Testingsgleadow
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesNarendra Pathai
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialAnup Singh
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
"Unit Testing for Mobile App" by Fandy Gotama  (OLX Indonesia)"Unit Testing for Mobile App" by Fandy Gotama  (OLX Indonesia)
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)Tech in Asia ID
 
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
Tech In Asia PDC 2017 - Best practice unit testing in mobile appsTech In Asia PDC 2017 - Best practice unit testing in mobile apps
Tech In Asia PDC 2017 - Best practice unit testing in mobile appsFandy Gotama
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With PytestEddy Reyes
 
Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slidesericholscher
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)jaxLondonConference
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
おっぴろげJavaEE DevOps
おっぴろげJavaEE DevOpsおっぴろげJavaEE DevOps
おっぴろげJavaEE DevOpsTaiichilow Nagase
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 

Mais procurados (20)

Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)
 
GeeCON 2012 hurdle run through ejb testing
GeeCON 2012 hurdle run through ejb testingGeeCON 2012 hurdle run through ejb testing
GeeCON 2012 hurdle run through ejb testing
 
Refactoring
RefactoringRefactoring
Refactoring
 
iOS Unit Testing
iOS Unit TestingiOS Unit Testing
iOS Unit Testing
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit TutorialJAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
 
Javascript Unit Testing
Javascript Unit TestingJavascript Unit Testing
Javascript Unit Testing
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
"Unit Testing for Mobile App" by Fandy Gotama  (OLX Indonesia)"Unit Testing for Mobile App" by Fandy Gotama  (OLX Indonesia)
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
 
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
Tech In Asia PDC 2017 - Best practice unit testing in mobile appsTech In Asia PDC 2017 - Best practice unit testing in mobile apps
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With Pytest
 
Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slides
 
Unit Testing in iOS
Unit Testing in iOSUnit Testing in iOS
Unit Testing in iOS
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Auto testing!
Auto testing!Auto testing!
Auto testing!
 
おっぴろげJavaEE DevOps
おっぴろげJavaEE DevOpsおっぴろげJavaEE DevOps
おっぴろげJavaEE DevOps
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 

Destaque

'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT Digital'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT DigitalJames Ford
 
Automation today 2006-08
Automation today 2006-08Automation today 2006-08
Automation today 2006-08wanglijie8512
 
The Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlandsThe Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlandsJames Ford
 
Diagnostico cerebral ninos
Diagnostico cerebral ninosDiagnostico cerebral ninos
Diagnostico cerebral ninosmelisa0610
 
Web 2.0 presentation
Web 2.0 presentationWeb 2.0 presentation
Web 2.0 presentationrhinorick5
 
Critique presentation
Critique presentationCritique presentation
Critique presentationcea_murphy
 
What does the future of technology hold
What does the future of technology holdWhat does the future of technology hold
What does the future of technology holdmaryyallison
 
The Magic of Charts
The Magic of ChartsThe Magic of Charts
The Magic of ChartsJames Ford
 
Reservation general
Reservation generalReservation general
Reservation generalSimon Malelo
 
Case study
Case studyCase study
Case studyajc0509
 
Operant Conditioning for the Classroom
Operant Conditioning for the ClassroomOperant Conditioning for the Classroom
Operant Conditioning for the ClassroomKarlaBe11a
 

Destaque (18)

'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT Digital'Hack to the future' - Hackathons at MMT Digital
'Hack to the future' - Hackathons at MMT Digital
 
Mari menulis nombor
Mari menulis nomborMari menulis nombor
Mari menulis nombor
 
Automation today 2006-08
Automation today 2006-08Automation today 2006-08
Automation today 2006-08
 
The Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlandsThe Flash Facebook Cookbook - FlashMidlands
The Flash Facebook Cookbook - FlashMidlands
 
Diagnostico cerebral ninos
Diagnostico cerebral ninosDiagnostico cerebral ninos
Diagnostico cerebral ninos
 
Web 2.0 presentation
Web 2.0 presentationWeb 2.0 presentation
Web 2.0 presentation
 
Mari menyebut nombor
Mari menyebut nomborMari menyebut nombor
Mari menyebut nombor
 
Critique presentation
Critique presentationCritique presentation
Critique presentation
 
What does the future of technology hold
What does the future of technology holdWhat does the future of technology hold
What does the future of technology hold
 
Mari menulis nombor
Mari menulis nomborMari menulis nombor
Mari menulis nombor
 
Paradis
ParadisParadis
Paradis
 
Fork me!
Fork me!Fork me!
Fork me!
 
Mari mengeja nombor
Mari mengeja nomborMari mengeja nombor
Mari mengeja nombor
 
Latihan
Latihan Latihan
Latihan
 
The Magic of Charts
The Magic of ChartsThe Magic of Charts
The Magic of Charts
 
Reservation general
Reservation generalReservation general
Reservation general
 
Case study
Case studyCase study
Case study
 
Operant Conditioning for the Classroom
Operant Conditioning for the ClassroomOperant Conditioning for the Classroom
Operant Conditioning for the Classroom
 

Semelhante a Testacular

Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014Alex Kavanagh
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testingMats Bryntse
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfEric Selje
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfEric Selje
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Dror Helper
 
Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 
Developer Test - Things to Know
Developer Test - Things to KnowDeveloper Test - Things to Know
Developer Test - Things to Knowvilniusjug
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dslKnoldus Inc.
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroPaul Boos
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 

Semelhante a Testacular (20)

Unit testing
Unit testingUnit testing
Unit testing
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 
Google test training
Google test trainingGoogle test training
Google test training
 
Developer Test - Things to Know
Developer Test - Things to KnowDeveloper Test - Things to Know
Developer Test - Things to Know
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dsl
 
DevOps - Boldly Go for Distro
DevOps - Boldly Go for DistroDevOps - Boldly Go for Distro
DevOps - Boldly Go for Distro
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 

Mais de James Ford

Virtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerVirtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerJames Ford
 
Telling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New RelicTelling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New RelicJames Ford
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanJames Ford
 
Responsive images in 10 minutes
Responsive images in 10 minutesResponsive images in 10 minutes
Responsive images in 10 minutesJames Ford
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deckJames Ford
 
What the HTML? - The Holy Grail
What the HTML? - The Holy GrailWhat the HTML? - The Holy Grail
What the HTML? - The Holy GrailJames Ford
 
Agile Partners
Agile PartnersAgile Partners
Agile PartnersJames Ford
 

Mais de James Ford (9)

Virtualisation - Vagrant and Docker
Virtualisation - Vagrant and DockerVirtualisation - Vagrant and Docker
Virtualisation - Vagrant and Docker
 
Telling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New RelicTelling Tales and Solving Crimes with New Relic
Telling Tales and Solving Crimes with New Relic
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
Web fonts FTW
Web fonts FTWWeb fonts FTW
Web fonts FTW
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawan
 
Responsive images in 10 minutes
Responsive images in 10 minutesResponsive images in 10 minutes
Responsive images in 10 minutes
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deck
 
What the HTML? - The Holy Grail
What the HTML? - The Holy GrailWhat the HTML? - The Holy Grail
What the HTML? - The Holy Grail
 
Agile Partners
Agile PartnersAgile Partners
Agile Partners
 

Último

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Testacular

  • 2. "Man, I just love unit tests, I've just been able to make a bunch of changes to the way something works, and then was able to confirm I hadn't broken anything by running the test over it again..."
  • 3. 1. Unit Tests allow you to make big changes to code quickly. You know it works now because you've run the tests, when you make the changes you need to make, you need to get the tests working again. This saves hours. 2. TDD helps you to realise when to stop coding. Your tests give you confidence that you've done enough for now and can stop tweaking and move on to the next thing. 3. The tests and the code work together to achieve better code. Your code could be bad / buggy. Your TEST could be bad / buggy. In TDD you are banking on the chances of BOTH being bad / buggy being low. Often it's the test that needs fixing but that's still a good outcome. 4. TDD helps with coding constipation. When faced with a large and daunting piece of work ahead writing the tests will get you moving quickly. 5. Unit Tests help you really understand the design of the code you are working on. Instead of writing code to do something, you are starting by outlining all the conditions you are subjecting the code to and what outputs you'd expect from that. Why Unit Test Javascript? part 1
  • 4. 6. Unit Tests give you instant visual feedback, we all like the feeling of all those green lights when we've done. It's very satisfying. It's also much easier to pick up where you left off after an interruption because you can see where you got to - that next red light that needs fixing. 7. Contrary to popular belief unit testing does not mean writing twice as much code, or coding slower. It's faster and more robust than coding without tests once you've got the hang of it. Test code itself is usually relatively trivial and doesn't add a big overhead to what you're doing. This is one you'll only believe when you're doing it :) 8. I think it was Fowler who said: "Imperfect tests, run frequently, are much better than perfect tests that are never written at all". 9. Good unit tests can help document and define what something is supposed to do 10. Unit tests help with code re-use. Migrate both your code AND your tests to your new project. Tweak the code till the tests run again. Why Unit Test Javascript? part 2
  • 5. ● Sanity testing - Are the expected functions and classes available? ● Regression testing - Is that bug squashed, and will never appear again? ● Functional testing - Given x, do y. ● Specification tests - I don't have real world data, but assuming I get data in this format... ● Edge-case testing - This expects a Number, but if someone gives it a String... Why do we use Unit Testing?
  • 7. ● Developed + Open Sourced by Google. ● Node.js === Native Javascript, using the V8 framework. ● Works with any* browser. ● Works without any IDE. ● Integration with CI servers. ● Stable. ● Fast. ● Line, branch, statement & function coverage test data. ● Jasmine, Mocha & AngularJS testing frameworks. Why Testacular?
  • 8. ● It can't evaluate code coverage in any more depth than line coverage. ● It's Java based. ● Slower than Testacular. Why not JSTestDriver?
  • 9. ● Configuration file specifies: ○ Input files (source code and test files) ○ Browsers to test with ○ Excluded files, coverage tests, ports, run mode, output format, base path, etc... ● Command line execution: > testacular start How does it work?
  • 10.
  • 11. Let's see that in action...
  • 13. Sanity testing /js/rio.js var RIO = { init: initialise, model: new RIOModel(), data: new RIOData(), controller: new RIOController() }; /tests/rio.tests.js describe("RIO Object", function() { it("has the expected API", function() { expect(RIO).toBeDefined(); expect(typeof(RIO)).toBe("object"); expect(typeof(RIO.init)).toBe("function"); expect(typeof(RIO.model)).toBe("object"); expect(typeof(RIO.data)).toBe("object"); expect(typeof(RIO.controller)).toBe("object"); }); });
  • 14. Regression testing /tests/regression.test.js describe("Defect DE248 Regression test", function() { beforeEach(function() { readFixtures('simple-fixture.html'); var options = { containerElement: $('div.sample-1'), dataProvider: Standalone.DataProvider, pathToAssets: "base/mockdata/mfl/" }; var activeTextInstance = new ActiveText(options); }); it("stops the iframes overlapping", function() { var iframeWidth = $('div.sample-1').find('div.iframe').width(); var dpsWidth = $('div.sample-1').find('div.reader').width(); expect(iframeWidth < dpsWidth).toBeTruthy(); expect(iframeWidth).toBeCloseTo(dpsWidth / 2); }); });
  • 15. Functional testing /tests/utils.tests.js describe("Functional tests for the utils class", function() { it('checks the output of getCorrectPathToAssetsFromHTMLPageAt', function() { var instance = new ActiveText.Loader({ pathToAssets: "mockdata/exploringscience/" }); var output = instance.test.getCorrectPathToAssetsFromHTMLPageAt( "images/page0001Exploring_Science_AT_v1.pdf.png"); expect(output).toBe("mockdata/exploringscience/images/"); ... }); });
  • 16. Specification testing /tests/specification.test.js $.ajaxSetup({ async: false }); $.mockjax({ url: 'mockdata/sockosaurus/META-INF/container.xml', responseType: "xml", responseText: '<?xml version="1.0" encoding="UTF-8"?><container version=" 1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container" ><rootfiles><rootfile full-path="OPS/book.opf" media-type="application/oebps- package+xml"/></rootfiles></container>' }); describe("Data Loader test", function() { it("loads data", function() { activeTextInstance.loader.loadData(); expect(activeTextInstance.data.getPath()).toBe("OPS/book.opf"); }); });
  • 17. Edge-case testing /tests/edgecase.tests.js describe("Navigation tests", function() { it("tests the edge cases", function() { activeTextInstance.navigation.gotoPage(5); expect(activeTextInstance.model.getCurrentPageNumber()).toBe(5); activeTextInstance.navigation.gotoPage(12); expect(activeTextInstance.model.getCurrentPageNumber()).toBe(12); activeTextInstance.navigation.gotoPage(-500); expect(activeTextInstance.model.getCurrentPageNumber()).toBe(0); activeTextInstance.navigation.gotoPage(500); expect(activeTextInstance.model.getCurrentPageNumber()).toBe(26); }); });
  • 18. ● describe(name, function) ● it(name, function) ● beforeEach(function) / afterEach(function) ● expect(condition).toBe(value); ● expect(condition).not.toBe(value); ● .toEqual() / .toBeTruthy() / .toBeFalsy() ● waitsFor(function) / runs(function) describe("A suite", function() { it("contains spec with an expectation", function() { expect(true).toBe(true); expect(true).not.toBe(false); }); }); Writing tests in Jasmine
  • 20. Python 2.7 node.js + npm testacular Growl Notifications PhantomJS http://www.python.org/download/releases/ http://nodejs.org/ http://testacular.github.com/0.6.0/intro/ installation.html http://www.growlforwindows.com/gfw/ http://phantomjs.org/ Installing Testacular + Jasmine Optional Extras
  • 22. Time to write some tests...
  • 23. Time to write some code...
  • 24. How many tests do you need?
  • 25.
  • 26. // Testacular configuration // base path, that will be used to resolve files and exclude basePath = ''; // list of files / patterns to load in the browser files = [ JASMINE, JASMINE_ADAPTER, 'js/**/*.js', 'js-tests/**/*.js' ]; // list of files to exclude exclude = []; preprocessors = { 'js/**/*.js' : 'coverage' }; coverageReporter = { type: 'lcov', dir: 'coverage/' }; // test results reporter to use // possible values: 'dots', 'progress', 'junit' reporters = ['progress', 'coverage']; // web server port port = 7654; Testacular configuration file + coverage // cli runner port runnerPort = 9100; // enable / disable colors in the output (reporters and logs) colors = true; // level of logging // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG logLevel = LOG_INFO; // enable / disable watching file and executing tests whenever any file changes autoWatch = true; // Start these browsers, currently available: // - Chrome // - ChromeCanary // - Firefox // - Opera // - Safari (only Mac) // - PhantomJS // - IE (only Windows) browsers = ['PhantomJS']; // If browser does not capture in given timeout [ms], kill it captureTimeout = 60000; // Continuous Integration mode // if true, it capture browsers, run tests and exit singleRun = false;
  • 27. That's all folks @psyked_james / aka James Ford