Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Test Driven Development Jon Kruger Blog: Twitter: JonKruger.

Similar presentations


Presentation on theme: "Using Test Driven Development Jon Kruger Blog: Twitter: JonKruger."— Presentation transcript:

1 Using Test Driven Development Jon Kruger Email: jon@jonkruger.com Blog: http://jonkruger.com Twitter: JonKruger

2 Explain why you should write unit tests Show you how to write unit tests for JavaScript code Show you Test Driven Development in action!

3

4

5 Tests a small unit of functionality Must run fast Isolate external dependencies using mocks and stubs

6 Test that runs against external dependencies (e.g. database, UI, file system) Test that is slow Web tests, load tests, performance tests

7 You will write bad code You (or someone else) will break your code Someone else will need to understand your code No compiler for JavaScript Peace of mind

8 Proof that your code works Fewer bugs (both now and in the future) Peace of mind

9

10 1. Design Edge cases Separation of concerns 2. Verification 3. Documentation 4. Testable code 5. When you’re “done” your done

11 Get Specs (features or bugs) Write tests Watch ‘em fail Write code Watch ‘em pass Repeat!

12 http://PairProgrammingBot.com

13 ?

14 JSUnitJ3Unit QUnitJSSpec YUI TestScrew-Unit JSNUnitscript.aculo.us unit testing TestCaseCrosscheck RhinoUnitjqUnit more?

15

16 QUnit JSSpec YUI Test Screw-Unit

17

18

19

20 QUnit Basics

21

22

23 Untestable JavaScript

24 Test won’t run unless it’s run from a page that contains these elements.

25

26 Testing this method will pop up an alert box!

27

28 Unable to test asynchronous AJAX calls.

29

30

31 ?

32

33

34

35

36

37

38

39

40

41

42

43

44 Get Specs (features or bugs) Write tests Watch ‘em fail Write code Watch ‘em pass Repeat!

45

46 Need to inject UI elements into the tests

47 I know that my code works I know what my code is supposed to do - tests are my documentation of my code I know that my code will continue to work My classes are well-designed Tests and good design will mean that it will be easier to make changes to the code Peace of mind!

48 Hold yourself to higher standard If your code sucks, then stop writing sucky code. Make quality a priority

49 ?

50 QUnit home page http://docs.jquery.com/QUnit Integrating QUnit tests into a continuous integration build http://tinyurl.com/qunitbuild MiniSudoku source code http://jonkruger.com/minisudoku/source.php My blog http://jonkruger.com Send me an email! jon@jonkruger.com Twitter http://twitter.com/jonkruger


Download ppt "Using Test Driven Development Jon Kruger Blog: Twitter: JonKruger."

Similar presentations


Ads by Google