TDD Basics with Angular.js and Jasmine
Upcoming SlideShare
Loading in...5
×
 

TDD Basics with Angular.js and Jasmine

on

  • 2,963 views

Basics of TDD with a small example using Angular.js and Jasmine

Basics of TDD with a small example using Angular.js and Jasmine

Statistics

Views

Total Views
2,963
Views on SlideShare
2,512
Embed Views
451

Actions

Likes
2
Downloads
23
Comments
0

3 Embeds 451

http://www.scoop.it 412
https://twitter.com 20
http://www.slideee.com 19

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • The ancient Greeks… :D
  • Very simple methodology.
  • About feedback, it is more important than we can think, to find a problem when developing is less costly than in further stages.
  • About feedback, it is more important than we can think, to find a problem when developing is less costly than in further stages.
  • All we know what are bugs.Find a bug involves too many people working too many hours, for something that, at the moment we don’t know is failing for business logic or because our code is not doing what it should.
  • 1. you can't be confident of your test if it doesn't fail in a so basic case like this.2. do not mix other functionalities, this could make your test more complex.4. Despite that we can think, TDD is not about finding bugs, is more about Designing software components robustly.
  • 2. … and compilation failures are failures.… in one word, FOCUS
  • 4 …BUT do not add any unnecessary features or code
  • I though that at least we could create the minimum necessary, before create the code.
  • Refactor? In this case we could comment and nothing more else.
  • YAGNI: YOU AREN’T GONNA NEED ITSoC: Separation of concerns, divide your system into modules or layers, each with a distinct area of responsibility.

TDD Basics with Angular.js and Jasmine TDD Basics with Angular.js and Jasmine Presentation Transcript

  • TDD (Test-Driven Development)
  • what is TDD? Write automated tests before you write your code. Some benefits: • Do not write more code than needed. • We have a goal to shoot for. • You can’t cheat and blow off the tests. • TDD helps design our code.
  • Why TDD? Be confident about our code. Be confident when someone make changes on it. Provides immediate feedback for every change.
  • Why TDD? Be confident about our code. Be confident when someone make changes on it. Provides immediate feedback for every change.
  • Bugs Are a waste of time. Are expensive to fix. “If I don’t need to make it work, I can go a lot faster.” Kent Beck
  • Unit test must… Initially fail. Be orthogonal (independent) to all the others. Don’t test configuration settings. Be not about finding bugs. • this is done manually by QA.
  • You are not allowed… To write code unless is to make pass a failing unit test. To write any more of a unit test than is sufficient to fail. To write any more production code than is sufficient to pass the one failing unit test.
  • Basic steps Create test. Check that this test fails. Once the test fails, start coding until the test does not fail. Once the code works, clean up, refactor all necessary.
  • Flow (Re)Write a test Test succeeds Check if test fails Test fails Write production code Test(s) fail Run all tests All tests succeed Clean up code
  • How to integrate it? Creating a filter: angular.module(‘app’, []) .filter(‘encode’, function() { return function(input) { // @todo write the code here }; });
  • How to integrate it? Let’s create the test: describe(‘Testing’, function() { var encodeFilter; beforeEach(module(‘app’)); beforeEach(inject(function($filter) { encodeFilter = $filter(‘encode’); })); it(‘should encode a URL with unusual characters’, function() { var url = ‘http://www.foo.com/234234/Build & Joneséí%’; var urlexpected = ‘’; expect(encodeFilter(url)).toBe(url); }); });
  • How to integrate it? Now the test fails...
  • How to integrate it? Now let’s write the code: angular.module(‘app’, []) .filter(‘encode’, function() { return function(input) { return encodeURI(input); }; });
  • How to integrate it? Now the test works! Refactor?
  • Concepts!
  • Some examples Testing a filter: http://jsfiddle.net/kFLuV/1/ Testing a directive: http://jsfiddle.net/Fh3V7/ Testing a controller: http://jsfiddle.net/ntFKL/ Testing a service: http://jsfiddle.net/B72tr/