Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver ...
Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver ...
Unit Testing increases the code quality
Unit Testing, TDD and
JavaScript Testing
Frameworks
Testing Types
Overview of Unit...
WHY Unit Testing
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Types of Tests
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Overview
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
What is Unit Test
–Verifies an atomic pie...
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Why Unit Testing
Consider building a car
from start to finish,
each of the parts which
make the engine, the
chassis, the w...
Unit Tests are written by developers!
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
 Increase c...
Test is not a Unit if
Interact over parts of system.
Take too much time to execute (>0.01 Sec).
Require Manual Setup.
Sika...
Unit Test Best Practices
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
1. Consistent
2. Atomic
3...
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Single Responsibility
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
1. One condition per test
2....
Unit Test Best Practices
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Difficult Scenarios
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Difficult Scenarios
Continue..
– Mocks
– Stubs
– Fake
Levels of TDD
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
– Acceptance TDD(ATDD)
– Developer T...
Test Driven Development
•Write Test
•Fail the test
•Write Minimum Code
•Pass the test
•Re factor Code
•Meet standards
Sika...
Why Test Driven Development
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awai...
Unit Testing and TDD
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Rules for Extreme Programming
1. User stories (pla...
XP– Contd.
Comparison of JS Unit Testing Frameworks
Framework Suitable for
Direct access to
JavaScript DOM API
Remote
control
File
wa...
Jasmine Framework
• Jasmine is a behavior-driven development framework for testing your JavaScript
code. It does not depen...
Jasmine Framework: Syntax
Jasmine aims to be easy to read. A simple hello world test looks like this:
describe('Hello worl...
Jasmine Framework: Test Suite and Test Cases
describe('MyApp Test Suite:', function() { });
• The above “Describe” block d...
Example
Example
Jasmine Framework: Spec and JS Code
A Jasmine test case is written as follows:
// your applications custom code
function a...
Jasmine Framework: Spec Runner (Running the Unit Tests)
Launching the SpecRunner.html file in your local browser runs the ...
Jasmine Framework: Pros and Cons
Pros:
• Should not be tied to any browser, framework, platform, or host language.
• Shoul...
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awai...
Jasmine can Use with
• Ruby (with or without Rails)
• Spider Monkey
• Node.js
• JS Test Driver
• Java (with Maven)
• DOT N...
Testing in Angular JS
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
References
http://evanhahn.com/how-do-i-jasmine/
http://pivotal.github.io/jasmine/
http://stackoverflow.com/questions/3008...
Q&A
Thanks for Attending
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
TDD, unit testing and java script testing frameworks workshop
Upcoming SlideShare
Loading in...5
×

TDD, unit testing and java script testing frameworks workshop

992

Published on

Published in: Software, Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
992
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
20
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

TDD, unit testing and java script testing frameworks workshop

  1. 1. Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
  2. 2. Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products. Unit Testing, Test Driven Development and JavaScript Testing Frameworks Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  3. 3. Unit Testing increases the code quality Unit Testing, TDD and JavaScript Testing Frameworks Testing Types Overview of Unit Testing Best Practices Some Difficult Scenarios Levels of TDD Test Driven Development TDD and Agile Extreme Programming Comparison of available JS Testing frameworks Introduction to Jasmine Framework Examples Jasmine Framework practical's Karma Framework practical’s Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  4. 4. WHY Unit Testing Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  5. 5. Types of Tests Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  6. 6. Overview Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer What is Unit Test –Verifies an atomic piece of code –Test on specific behavior –Each test is autonomous
  7. 7. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  8. 8. Why Unit Testing Consider building a car from start to finish, each of the parts which make the engine, the chassis, the wheels, must be individually verified to be in working order before they are to be assembled into a 'car'. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  9. 9. Unit Tests are written by developers! Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer  Increase confidence in code  Fearlessly change your code  Discover usability issues early
  10. 10. Test is not a Unit if Interact over parts of system. Take too much time to execute (>0.01 Sec). Require Manual Setup. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  11. 11. Unit Test Best Practices Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer 1. Consistent 2. Atomic 3. Single Responsibility 4. Self Descriptive
  12. 12. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  13. 13. Single Responsibility Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer 1. One condition per test 2. One reason to change
  14. 14. Unit Test Best Practices Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  15. 15. Difficult Scenarios Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  16. 16. Difficult Scenarios
  17. 17. Continue.. – Mocks – Stubs – Fake
  18. 18. Levels of TDD Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer – Acceptance TDD(ATDD) – Developer TDD
  19. 19. Test Driven Development •Write Test •Fail the test •Write Minimum Code •Pass the test •Re factor Code •Meet standards Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  20. 20. Why Test Driven Development Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  21. 21. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer TDD is not about Testing TDD is about –Design and Development •By testing first you design your code
  22. 22. Unit Testing and TDD Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  23. 23. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  24. 24. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer Rules for Extreme Programming 1. User stories (planning) 2. Small releases 3. Metaphor (standardized naming schemes) 4. Collective ownership 5. Coding standard: 6. Simple design 7. Refactoring 8. TDD 9. Pair programming 10.Continuous integration 11.40-hour workweek 12.On-site customer
  25. 25. XP– Contd.
  26. 26. Comparison of JS Unit Testing Frameworks Framework Suitable for Direct access to JavaScript DOM API Remote control File watching File preprocessing Tests written in Karma unit yes yes yes yes yes any JSTestDriver unit yes yes yes no no JS Selenium e2e no yes yes no no any WebDriver e2e no yes yes no no any Jasmine unit yes yes no no no JS Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  27. 27. Jasmine Framework • Jasmine is a behavior-driven development framework for testing your JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. Jasmine API includes features such as: • A more natural BDD syntax for organizing the test logic than JUnit style assertion test frameworks • Asynchronous testing • Mocks • Easy to create custom matchers • Ability to share or isolate behaviors between tests within a spec encapsulating parts of your spec. • Continuous integration support Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  28. 28. Jasmine Framework: Syntax Jasmine aims to be easy to read. A simple hello world test looks like this: describe('Hello world', function() { it('says hello', function() { expect(helloWorld()).toEqual("Hello world!"); }); }); Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  29. 29. Jasmine Framework: Test Suite and Test Cases describe('MyApp Test Suite:', function() { }); • The above “Describe” block defines the test suite in Jasmine, in test suite single or multiple test cases can be written. it('Should contain no JavaScript coding errors!', function() { expect(errorCount).toBe(0); }); • This above “It” block is representing the test cases which can written in Describe block. Expect showing the expected result for the particular test case. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  30. 30. Example
  31. 31. Example
  32. 32. Jasmine Framework: Spec and JS Code A Jasmine test case is written as follows: // your applications custom code function addValues( a, b ) { return a + b; }; // the Jasmine test code describe("addValues(a, b) function", function() { it("should equal 3", function(){ expect( addValues(1, 2) ).toBe( 3 ); }); it("should equal 3.75", function(){ expect( addValues(1.75, 2) ).toBe( 3.75 ); }); it("should NOT equal '3' as a String", function(){ expect( addValues(1, 2) ).not.toBe( "3" ); }); }); Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  33. 33. Jasmine Framework: Spec Runner (Running the Unit Tests) Launching the SpecRunner.html file in your local browser runs the tests. Jasmine provides a nice view of the test results. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  34. 34. Jasmine Framework: Pros and Cons Pros: • Should not be tied to any browser, framework, platform, or host language. • Should have idiomatic and unsurprising syntax. • Should work anywhere JavaScript can run, including browsers, servers, phones, etc. • Shouldn't intrude in your application's territory (e.g. by cluttering the global namespace). • Should play well with IDEs (e.g. test code should pass static analysis). • It should integrate easily with continuous build systems. • It should be simple to get started with. Cons: Not Much examples available Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  35. 35. Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer Basic general test cases Rainy Days Sencha Project unit tests Karma Practical App – ToDo App Practical Example
  36. 36. Jasmine can Use with • Ruby (with or without Rails) • Spider Monkey • Node.js • JS Test Driver • Java (with Maven) • DOT NET • PERL • Scala Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  37. 37. Testing in Angular JS Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  38. 38. References http://evanhahn.com/how-do-i-jasmine/ http://pivotal.github.io/jasmine/ http://stackoverflow.com/questions/300855/javascript-unit-test-tools-for-tdd http://docs.angularjs.org/tutorial http://edspencer.net/2013/07/28/jasmine-and-jenkins-continuous-integration/ http://stackoverflow.com/questions/3459287/whats-the-difference-between-a-mock- stub Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  39. 39. Q&A Thanks for Attending Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×