Test-Driven Development of AngularJS ApplicationsFITC
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
OVERVIEW
AngularJS is an open-source JavaScript framework, maintained by Google, that simplifies development of single-page applications. This session will provide an overview of AngularJS framework and demonstrate test-driven development of single-page applications.
In this session Andy will present a walkthrough of Angular’s core features such as dependency injector and directives. He will showcase a test-driven development of AngularJS applications using Jasmine and explain Angular’s data bindings that allow for creation of views and controllers that update automatically in response to data changes. He will also demo Angular’s deep linking and front-end validations and present integration with Ruby On Rails back end using AngularJS AJAX abstractions. Finally, Andy will utilize AngularJS directives and components to create reusable UI elements.
In summary, AngularJS is a great framework for creating complex single-page applications. Attendees will leave the talk with a solid understanding of Angular’s test-driven development process.
JUnit is the de facto standard in Java testing. Yet many advanced JUnit features are little known and poorly understood. This session reviews some lesser-known features of JUnit, along with a few associated libraries, that can make your unit tests more powerful, expressive, and fun. The session is intended for Java developers, lead developers, and architects trying to introduce good testing practices into their teams.
Test-Driven Development of AngularJS ApplicationsFITC
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
OVERVIEW
AngularJS is an open-source JavaScript framework, maintained by Google, that simplifies development of single-page applications. This session will provide an overview of AngularJS framework and demonstrate test-driven development of single-page applications.
In this session Andy will present a walkthrough of Angular’s core features such as dependency injector and directives. He will showcase a test-driven development of AngularJS applications using Jasmine and explain Angular’s data bindings that allow for creation of views and controllers that update automatically in response to data changes. He will also demo Angular’s deep linking and front-end validations and present integration with Ruby On Rails back end using AngularJS AJAX abstractions. Finally, Andy will utilize AngularJS directives and components to create reusable UI elements.
In summary, AngularJS is a great framework for creating complex single-page applications. Attendees will leave the talk with a solid understanding of Angular’s test-driven development process.
JUnit is the de facto standard in Java testing. Yet many advanced JUnit features are little known and poorly understood. This session reviews some lesser-known features of JUnit, along with a few associated libraries, that can make your unit tests more powerful, expressive, and fun. The session is intended for Java developers, lead developers, and architects trying to introduce good testing practices into their teams.
This presentation deals with a complex approach to application testing in back end and front end parts, tests writing and common mistakes. It also includes a short overview of libraries and frameworks for creation of tests, as well as practical examples of code.
Presentation by Pavlo Iuriichuk, Lead Software Engineer, GlobalLogic, Kyiv), delivered at an open techtalk on December 11, 2014.
More details - http://globallogic.com.ua/report-web-testing-techtalk-2014
Advanced Jasmine - Front-End JavaScript Unit TestingLars Thorup
Code: https://github.com/larsthorup/jasmine-demo-advanced
Video: https://www.youtube.com/watch?v=g4eQplHxU18
Audio: https://www.youtube.com/watch?v=8FUwc3gZDMw
Unit testing front-end JavaScript presents its own unique set of challenges. In this session we will look at number of different techniques to tackle these challenges and make our JavaScript unit tests fast and robust. We plan to cover the following subjects:
* Mocking and spy techniques to avoid dependencies on
- Functions, methods and constructor functions
- Time (new Date())
- Timers (setTimeout, setInterval)
- Ajax requests
- The DOM
- Events
* Expressive matchers
- Jasmine-jQuery
* Structuring tests for reuse and readability
* Testing browser-specific behaviour
V1.0
How often do you get a bug report that you can’t reproduce?
How often do you struggle to find the source of the bug in your code?
How can you streamline the testing process and make sure you don’t repeat the same bugs?
With Visual Studio 2010 & Team Foundation Server (TFS) 2010 there are a lot of new features for testers and developers that will solve these problems.
In this session you will learn how to: automate more, reproduce bugs easier, maintain your tests and configuration and discover problems sooner.
from Peter Gfader
A high-level introduction to testing in EmberJS. This talk explains the difference between unit, integration and acceptance tests, when to use each and how to get started with ember-cli-mocha.
This presentation deals with a complex approach to application testing in back end and front end parts, tests writing and common mistakes. It also includes a short overview of libraries and frameworks for creation of tests, as well as practical examples of code.
Presentation by Pavlo Iuriichuk, Lead Software Engineer, GlobalLogic, Kyiv), delivered at an open techtalk on December 11, 2014.
More details - http://globallogic.com.ua/report-web-testing-techtalk-2014
Advanced Jasmine - Front-End JavaScript Unit TestingLars Thorup
Code: https://github.com/larsthorup/jasmine-demo-advanced
Video: https://www.youtube.com/watch?v=g4eQplHxU18
Audio: https://www.youtube.com/watch?v=8FUwc3gZDMw
Unit testing front-end JavaScript presents its own unique set of challenges. In this session we will look at number of different techniques to tackle these challenges and make our JavaScript unit tests fast and robust. We plan to cover the following subjects:
* Mocking and spy techniques to avoid dependencies on
- Functions, methods and constructor functions
- Time (new Date())
- Timers (setTimeout, setInterval)
- Ajax requests
- The DOM
- Events
* Expressive matchers
- Jasmine-jQuery
* Structuring tests for reuse and readability
* Testing browser-specific behaviour
V1.0
How often do you get a bug report that you can’t reproduce?
How often do you struggle to find the source of the bug in your code?
How can you streamline the testing process and make sure you don’t repeat the same bugs?
With Visual Studio 2010 & Team Foundation Server (TFS) 2010 there are a lot of new features for testers and developers that will solve these problems.
In this session you will learn how to: automate more, reproduce bugs easier, maintain your tests and configuration and discover problems sooner.
from Peter Gfader
A high-level introduction to testing in EmberJS. This talk explains the difference between unit, integration and acceptance tests, when to use each and how to get started with ember-cli-mocha.
Advanced QUnit - Front-End JavaScript Unit TestingLars Thorup
Code: https://github.com/larsthorup/qunit-demo-advanced
Unit testing front-end JavaScript presents its own unique set of challenges. In this session we will look at number of different techniques to tackle these challenges and make our JavaScript unit tests fast and robust. We plan to cover the following subjects:
* Mocking and spy techniques to avoid dependencies on
- Functions, methods and constructor functions
- Time (new Date())
- Timers (setTimeout, setInterval)
- Ajax requests
- The DOM
- Events
* Structuring tests for reuse and readability
* Testing browser-specific behaviour
* Leak testing
As a PHP developer, you've probably had to deal with Javascript at some point in your career. Some of the Javascript code you've written may even have been pretty complex. What happens if you need to make some changes? Will it break existing functionality? The only way to really know if everything is still working, is by unit testing your Javascript. This talk will introduce you to QUnit for creating Javascript unit tests and JsTestDriver for automating these tests.
Unit Testing in JavaScript with MVC and QUnitLars Thorup
While more and more application code move from the back-end to a JavaScript-based front-end, we still need to test this code efficiently. Testing JavaScript is often done using browser automation frameworks, but system-level testing is slow and brittle.
Here we present a way to structure your JavaScript application according to the Model-View-Controller (MVC) design pattern and how this enables us to write unit tests for a large part of the application logic, using a testing framework like QUnit.
Sample source code available at http://www.zealake.com/public/javascript-unit-testing.zip
Session from GIDS 2014, showing how to do automated Web testing using a variety of JavaScript frameworks, including QUnit, Jasmine, Protractor, Selenium, and PhantomJS
Testing, Performance Analysis, and jQuery 1.4jeresig
This is the talk that I gave at JSConf.eu 2009, then modified slightly and given again at the December Bayjax meetup (the parts on jQuery and HTML 5 in IE were added).
ArcBlock presents Elixir ExUnit. Learn how to write a unit test for Elixir code? This talk will give an introduction to ExUnit in Elixir, what components are included in it and how to use them.
Unit testing patterns for concurrent codeDror Helper
Getting started with unit testing is not hard, the only problem is that most programs are more than a simple calculator with two parameters and a returns value that is easy to verify.
Writing unit tests for multi-threaded code is harder still.
Over the years I discovered useful patterns that helped me to test multi-threaded and asynchronous code and enabled the creation of deterministic, simple and robust unit tests.
Come learn how to test code that uses concurrency and parallelism – so that the excuses of not writing unit tests for such code would become as obsolete as a single core processors.
This presentation describes the some of the major functionality of JUnit4 and TestNG .Each topic contains example so that a viewer can understand the usage and apply them in their code.
2. Points to Discuss
Unit Testing & Test Driven Development
QUnit
QUnit API
Automated Testing (a brief introduction)
3. Unit Testing
In computer programming, unit testing is a procedure
used to validate that individual modules or units of
source code are working properly.
Unit testing is used for
(i) Test Driven Development
(ii) Fixing bugs
(iii) Regression testing
4. Test Driven Development
Test-Driven Development (TDD) is a computer
programming technique that involves repeatedly first
writing a test case and then implementing only the code
necessary to pass the test.
Test-driven development is a method of designing
software, not merely a method of testing.
7. What do you need?
A Unit Testing framework
Development Environment
8. QUnit
QUnit is a powerful, easy-to-use JavaScript unit testing
framework.
It's used by the jQuery, jQuery UI and jQuery Mobile
projects and is capable of testing any generic JavaScript
code, including itself!
Supports the same browsers as jQuery 1.x. That's IE6+
and Current - 1 for Chrome, Firefox, Safari and Opera.
9. Getting Started
Just qunit.js, qunit.css, and a little bit of HTML
A Quick Demo:
http://jsfiddle.net/akankshaaro/rq31v84h/
10. QUnit API
Test
Assert
Async Control
Callback
11. Test : QUnit.test( name, test )
Adds a test to run.
Testing the most common, synchronous code
Qunit.test(“name of the test”, function() {
//write down the assertions
});
function: Function to close over assertions
12. Test : expect()
Specify how many assertions are expected to run within a
test.
If the number of assertions run does not match the
expected count, the test will fail.
test(”expected assertions", function() {
expect( 2 );
//two assertions are expected
});
14. Assert - ok()
ok( state, message )
A boolean check, passes if the first argument is truthy.
test("ok”, function() {
expect(3);
ok(true, "passes because true is true");
ok(1, "passes because 1 is truthy");
ok("", "fails because empty string is not truthy");
});
15. Assert - equal()
equal( actual, expected, message )
A comparison assertion that passes if actual == expected.
test("equal”, function() {
expect(3);
var actual = 5 - 4;
equal(actual, 1, "passes because 1 == 1");
equal(actual, true, "passes because 1 == true");
equal(actual, false, "fails because 1 != false");
});
16. Assert - notEqual()
notEqual( actual, expected, message )
A comparison assertion that passes if actual != expected.
test("notEqual”, function() {
expect(3);
var actual = 5 - 4;
notEqual(actual, 0, "passes because 1 != 0");
notEqual(actual, false, "passes because 1 != false");
notEqual(actual, true, "fails because 1 == true");
});
17. Assert - strictEqual()
strictEqual( actual, expected, message )
A comparison assertion that passes if actual === expected.
test("notEqual”, function() {
expect(3);
var actual = 5 - 4;
strictEqual(actual, 1, "passes because 1 === 1");
strictEqual(actual, true, "fails because 1 !== true");
strictEqual(actual, false, "fails because 1 !== false");
});
18. Assert - notStrictEqual()
notStrictEqual( actual, expected, message )
A comparison assertion that passes if actual !== expected.
test("notStrictEqual”, function() {
expect(3);
var actual = 5 - 4;
notStrictEqual(actual, 1, "fails because 1 === 1");
notStrictEqual(actual, true, "passes because 1 !== true");
notStrictEqual(actual, false, "passes because 1 !== false");
});
19. Assert - deepEqual ()
deepEqual( actual, expected, message )
Recursive comparison assertion, working on primitives,
arrays and objects, using ===.
test("deepEqual”, function() {
expect(3);
var actual = {a: 1};
equal( actual, {a: 1}, "fails because objects are different");
deepEqual(actual, {a: 1}, "passes because objects are equivalent");
deepEqual(actual, {a: "1"}, "fails because '1' !== 1");
});
20. Assert - notDeepEqual()
notDeepEqual( actual, expected, message )
Recursive comparison assertion. The result of deepEqual,
inverted.
test("notDeepEqual”, function() {
expect(3);
var actual = {a: 1};
notEqual( actual, {a: 1}, "passes because objects are different");
notDeepEqual(actual, {a: 1}, "fails because objects are equivalent");
notDeepEqual(actual, {a: "1"}, "passes because '1' !== 1");
});
21. Assert - throws()
Assertion to test if a callback throws an exception when
run and optionally compare the thrown error.
test("throws”, function() {
expect(3);
throws(
function() { throw new Error("Look me, I'm an error!"); },
"passes because an error is thrown inside the callback”
);
throws(
function() { x // ReferenceError: x is not defined },
"passes because an error is thrown inside the callback”
);
throws (
function() { var a = 1; },
"fails because no error is thrown inside the callback”
);
});
22. Tests Should be Atomic
Execution order cannot be guaranteed!
Each test should be independent from one another.
QUnit.test() is used to keep test cases atomic.
23. Async Control : QUnit.asyncTest
For testing asynchronous code, QUnit.asyncTest will
automatically stop the test runner and wait for your code
to call QUnit.start() to continue.
The following illustrates an asynchronous test that waits 1
second before resuming
QUnit.asyncTest( "asynchronous test: one second later!", function(
assert ) {
expect( 1 );
setTimeout(function() {
assert.ok( true, "Passed and ready to resume!" );
QUnit.start(); }, 1000);
});
24. Async Control : QUnit.stop()
Increase the number of QUnit.start() calls the testrunner
should wait for before continuing.
When your async test has multiple exit points, call
QUnit.stop() multiple times or use the increment
argument.
QUnit.test( "a test", function( assert ){
QUnit.stop();
setTimeout(function(){
assert.equals("somedata" , "someExpectedValue" );
QUnit.start(); }, 150 );
});
25. Grouping Tests : QUnit.module()
It groups tests together to keep them logically organized
and be able to run a specific group of tests on their own.
All tests that occur after a call to QUnit.module() will be
grouped into that module. The test names will all be
preceded by the module name in the test results.
QUnit.module( "group a" );//tests for module a
QUnit.module( "group b" );//test for module b
26. Grouping Tests : QUnit.module()
QUnit.module() can also be used to extract common code
from tests within that module.
The QUnit.module() function takes an optional second
parameter to define functions to run before and after
each test within the module
QUnit.module( "module", {
setup: function( assert )
{//any setup task},
teardown: function( assert )
{//task to be performed after test completion}
});
QUnit.test( "test with setup and teardown", function()
{
//test cases
});
27. Callbacks
When integrating QUnit into other tools like CI servers,
use these callbacks as an API to read test results.
QUnit.begin()
QUnit.done()
QUnit.moduleStart()
QUnit.moduleDone()
QUnit.testStart()
QUnit.testDone()