1 / 31

QUnit JavaScript Testing in the Enterprise

QUnit JavaScript Testing in the Enterprise. David Lee Oct. 11, 2011. Getting to Know You. How many of you work on Websites that use JavaScript? How many currently have a Unit Testing strategy ? About me. Outline for Today’s Talk. What’s A ll T his A bout Unit Testing ?

carolynv
Download Presentation

QUnit JavaScript Testing in the Enterprise

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. QUnit JavaScript Testing in the Enterprise David Lee Oct. 11, 2011

  2. Getting to Know You • How many of you work on Websites that use JavaScript? • How many currently have a Unit Testing strategy? • About me.

  3. Outline for Today’s Talk • What’s All This About Unit Testing? • What Do You Mean By JavaScript Unit Testing? • The QUnitFramework • The End Result

  4. What is Unit Testing? • What is all this hullaballoo about?

  5. What is Unit Testing? When the rubber meets the road testing is… • Developers code tests that • describe desired functionality, • access this functionality, • then verify that this functionality meets expectations • Reporting • Should include reporting • And scheduled test runs

  6. Unit Testing Takes Time • Unit testing requires up front time • Later this saves time for development and QA • Time spent up front includes: • Developer time: • Test creation --- coding of tests • Infrastructure Setup: • Automation of tests • Configuration of testing reports

  7. Unit Testing Has Many Benefits • Let’s see what some of these are…

  8. Unit Testing Benefits • Fewer bugs

  9. Unit Testing Gets Your Attention • Immediate feedback when code goes wrong (in a good way)

  10. A Time Saver • Overall the process of development, testing and dealing with bugs takes less time

  11. And What else... • Intercepts errors before they happen • Keeps developers focused on the requirements • Reduces workload on QA / Dev

  12. JavaScript Unit Testing? • Why test JavaScript? • Typical unit testing strategies • JavaScript unit testing strategies • Problems being near the UI

  13. Why JavaScript Testing? • More and more technologies bring the logic client-side: • JSON • JQuery • AJAX • HTML5 • HTML5 for Mobile devices • Richer client-side experiences lead to more JavaScript

  14. Why JavaScript Unit Testing? • With more JavaScript in the client there is more opportunity for code errorsin JavaScript • Relevant behaviors remain untested when ignoring JavaScript

  15. Typical Unit Testing Strategies Typically unit testing is done on application code residing in the middle layer User Interface Unit Testing Application Code Data Access

  16. JavaScript Unit Testing Strategies But JavaScriptunit testing is done on script thatresides in or near the user interface User Interface Unit Testing JavaScript Application Code Data Access

  17. Problems being near the UI • JavaScript & HTML are hard to separate • Problems relying on HTML

  18. JavaScript &HTML are hard to separate • Historically JavaScript & HTML are inseparable • JQuery make it harder to separate JavaScript from HTML $(".className > div").empty();

  19. Problems Relying on HTML • Testing strategies say to test logic and not the User Interface • If we rely on HTML it can cause problems: • HTML is fluid (changeable) • Controls, add-ins, database records, etc. all change HTML • Designers & Programmers (two hands in the mix)

  20. How to test, but include HTML? • Option 1: Copy HTML for our tests? • Option 2: Run our tests directly against the web page? • Option 3: Not test JavaScript that has a relationship to HTML • Option 4: Some sort of hybrid approach

  21. Option 1: Copy HTML for our tests? • HTML may be required, so should we copy it for our tests? Static HTML may become old and irrelevant

  22. Option 1: Copy HTML for our tests? Copy HTML

  23. Option 2: Run tests against the page • Tests could modify or significantly change the behavior / look /feel of a web page • Example: running a test that inserts a block of text… what happens at the end of the test.

  24. Option 3: Avoid HTML Altogether • We ruled this out because it limited the number of tests we were able to create. • Many pages with significant JavaScript would remain untested.

  25. The QUnit Framework • A look at QUnitexamples

  26. The End Result • Our HTML Hybrid Testing Strategy • Our JavaScript Testing Strategy

  27. Our HTML Hybrid Testing Strategy • Runs tests in an IFRAME • Copies HTML from the actual page immediately

  28. Our JavaScript Testing Strategy • Make it easy to wire in tests • Use site-wide hooks to keep the developer’s job easy • Put test failures and successes in plain view

  29. And Some Final Thoughts… • Unit Testing is a valuable resource for YOU! • The Use of JavaScript Unit Testing is timely and relevant given today’s technologies. • To either deny or use HTML in your JavaScript tests will take forethought. In many cases it is not a simple decision. • The provided libraries and sample tests will hopefully give you a jump start into the world of JavaScript Unit Testing.

  30. Questions • Questions?

  31. QUnit JavaScript Testing in the Enterprise Thank you!

More Related