TAILIEUCHUNG - Test Driven JavaScript Development- P4

Test Driven JavaScript Development- P4:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | Summary 53 Although we visited the topics of test coverage reports and continuous integration in this chapter no setup or examples were given for such tools. On the book s website1 you will find a guide to running the Coverage plugin for JsTestDriver as well as a guide on how to run JsTestDriver tests in the open source continuous integration server Hudson. In the next chapter we will have a look at some other ways to utilize unit tests before we move on to Part II JavaScript for Programmers. 1. http Please purchase PDF Split-Merge on to remove this watermark. From the Library of This page intentionally left blank Please purchase PDF Split-Merge on to remove this watermar From the Library of T tt T rn Test to Learn I n the previous three chapters we have seen how automated tests can help improve quality of code guide design and drive development. In this chapter we will use automated tests to learn. As small executable code examples unit tests make a perfect learning resource. Isolating a specific aspect of an interface in a unit test is a great way to learn more about how it behaves. Other types of automated tests can help our understanding of both the language and specific problems. Benchmarks are a valuable tool to measure relative performance and can guide decisions about how to solve a specific problem. Exploring JavaScript with Unit Tests Quickly executing JavaScript as in executing a few lines of script to explore the behavior of some object is fairly simple. Most modern browsers ship with a console that serves this purpose just fine. Additionally there are several options for JavaScript command line interfaces when the browser environment is not of particular interest. Although this sort of one-off coding session can help our understanding of an interface it suffers from the same problems that manual application testing does. There is no way to repeat a given experiment there is no