Free Sample
+ Collection

JavaScript Testing Beginner's Guide

Beginner's Guide
Yuxian, Eugene Liang

Test and debug JavaScript the easy way.
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849510004
Paperback272 pages

About This Book

Learn different techniques to test JavaScript, no matter how long or short your code might be. Discover the most important and free tools to help make your debugging task less painful. Discover how to test user interfaces that are controlled by JavaScript. Make use of free built-in browser features to quickly find out why your JavaScript code is not working, and most importantly, how to debug it. Automate your testing process using external testing tools.  

Who This Book Is For

Beginner JavaScript developers looking for essential ways to write, test, and debug JavaScript for different purposes and situations.

Table of Contents

Chapter 1: What is JavaScript Testing?
Where does JavaScript fit into the web page?
Time for action—building a HTML document
Time for action—styling your HTML document using CSS
Time for action—giving behavior to your HTML document
The difference between JavaScript and server-side languages
Why pages need to work without JavaScript
What is testing?
Why do you need to test?
Types of errors
Time for action—loading errors in action
Time for action—loading errors in action
Time for action—runtime errors in action
Time for action—logic errors in action
Some advice for writing error-free JavaScript
Chapter 2: Ad Hoc Testing and Debugging in JavaScript
The purpose of ad hoc testing—getting the script to run
What happens when the browser encounters an error in JavaScript
Browser differences and the need to test in multiple browsers
Time for action—checking for features and sniffing browsers
Time for action—capability testing for different browsers
Are you getting the correct output and putting values in the correct places?
Time for action—accessing values from a form
Time for action—getting the correct values in the correct places
Does the script give the expected result?
What to do if the script doesn't run
Time for action—using alert to inspect your code
Time for action—unobtrusively checking what values are used
Commenting out parts of the script to simplify testing
Time for action—simplifying the checking process
Timing differences—making sure that the HTML is there before interacting with it
Why ad hoc testing is never enough
Chapter 3: Syntax Validation
The difference between validating and testing
Code quality
Common errors in JavaScript that will be picked up by validation
JSLint—an online validator
Time for action—using JSLint to spot validation errors
Valid code constructs that produce validation warnings
How to fix validation errors
Time for action—fixing "use strict" errors
Time for action—fixing the error of "Unexpected use of ++"
Time for action—fixing the error of "Functions not defined"
Time for action—fixing the error of using too many var statements
Time for action—fixing the expectation of '<\/' instead of '</'
Time for action—changing == to ===
Time for action—fixing "Alert is not defined"
Time for action—avoiding HTML event handlers
JavaScript Lint—a tool you can download
Chapter 4: Planning to Test
A very brief introduction to the software lifecycle
Do you need a test plan to be able to test?
When to develop the test plan
How much testing is required?
Major testing concepts and strategies
Testing order
Documenting your test plan
Chapter 5: Putting the Test Plan Into Action
Applying the test plan: running your tests in order
Time for action—Test Case 1a: testing expected and acceptable values by using white box testing
Time for action—Test case 1bi: testing expected but unacceptable values using boundary value testing
Time for action—Test case 1bii: testing expected but unacceptable values using illegal values
Time for action—testing the program logic
Time for action—Test Case 3a: testing the entire program with expected values
Time for action—Test Case 3b: testing robustness of the second form
Regression testing in action
Time for action—fixing the bugs and performing regression testing
Chapter 6: Testing More Complex Code
Issues with combining scripts
Using JavaScript libraries
Deliberately throwing your own JavaScript errors
Trapping errors by using built-in objects
Using the error console log
Modifying scripts and testing
Time for action—coding, modifying, throwing, and catching errors
Chapter 7: Debugging Tools
IE 8 Developer Tools (and the developer toolbar plugin for IE6 and 7)
Using IE developer tools
Time for action—debugging HTML by using the IE8 developer tool
Time for action—debugging CSS by using the IE8 developer tool
Time for action—more Debugging JavaScript by using the IE8 developer tool
Safari or Google Chrome Web Inspector and JavaScript Debugger
Time for action—debugging with Chrome
Opera JavaScript Debugger (Dragonfly)
Time for action—debugging with Opera Dragonfly
Firefox and the Venkman extension
Time for action—debugging using Firefox's Venkman extension
Time for action—more debugging with the Venkman extension
Firefox and the Firebug extension
Chapter 8: Testing Tools
Time for action—user Interface testing using Sahi
Time for action testing JavaScript with QUnit
Time for action—creating ad hoc JavaScript benchmark tests
More testing tools that you should check out

What You Will Learn

Relationship between HTML, CSS, and JavaScript Different types of JavaScript error How to perform ad hoc testing How to validate your JavaScript code Different testing concepts Create a test plan and implement it How to test more complex code by using JavaScript’s exception handling Learn how to test the user interface controlled by JavaScript How to debug your code using tools such as Google Chrome, Javascript Debugger, and Firefox's Venkman Extension. How to further automate your testing process using Sahi, Qunit, and JsLitmus Other testing tools that will make your testing process easier and less painful  

In Detail

JavaScript is an important part of web development in today’s Web 2.0 world. While there are many JavaScript frameworks in the market, learning to write, test, and debug JavaScript without the help of any framework will make you a better JavaScript developer. However, testing and debugging can be time consuming, tedious, and painful. This book will ease your woes by providing various testing strategies, advice, and tool guides that will make testing smooth and easy. This book shows you the most essential features of JavaScript, which you will be using in your daily development, testing, and debugging tasks. You will learn to use the most basic functions of JavaScript to perform ad hoc testing quickly and efficiently. This book is organized in an easy to follow, step-by-step tutorial style to maximize your learning. You will first learn about the different types of errors you will most often encounter as a JavaScript developer. You will also learn the most essential features of JavaScript through our easy to follow examples.As you go along, you will learn how to write better JavaScript code through validation. Learning how to write validated code alone will help you improve tremendously as a JavaScript developer and most importantly, to write JavaScript code that runs better, faster, and with less bugs.As our JavaScript program gets larger, we need better ways of testing our JavaScript code. You will learn how to go about various testing concepts and how to use them in your test plan. After which, you will learn how to implement the test plan for your code. To accommodate more complex JavaScript code, you will learn more about the built-in features of JavaScript to identify and catch different types of JavaScript error. Such information helps to spot the root of the problem so that you can act on it. Finally, you will learn how to make use of the built-in browser tools and other external tools to automate your testing process.


Read More