TDD, unit testing and java script testing frameworks workshop
Upcoming SlideShare
Loading in...5
×
 

TDD, unit testing and java script testing frameworks workshop

on

  • 516 views

 

Statistics

Views

Total Views
516
Views on SlideShare
510
Embed Views
6

Actions

Likes
1
Downloads
10
Comments
0

1 Embed 6

http://www.slideee.com 6

Accessibility

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

TDD, unit testing and java script testing frameworks workshop TDD, unit testing and java script testing frameworks workshop Presentation Transcript

  • Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
  • 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
  • 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
  • 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 piece of code –Test on specific behavior –Each test is autonomous
  • 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 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
  • 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
  • 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
  • Unit Test Best Practices Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer 1. Consistent 2. Atomic 3. Single Responsibility 4. Self Descriptive
  • 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. One reason to change
  • 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 TDD
  • 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
  • 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 Awais | Software Engineer TDD is not about Testing TDD is about –Design and Development •By testing first you design your code
  • 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 (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
  • XP– Contd.
  • 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
  • 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
  • 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
  • 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
  • Example
  • Example
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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/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
  • Q&A Thanks for Attending Sikandar Ahmed | Lead Software Engineer Ahmad Awais | Software Engineer