NodeJS:                         Writing Tests                           A Beginners’ Guide                   Docs: http://...
Why write tests?Wednesday, April 3, 13
Programming should be funWednesday, April 3, 13
...and not                         frustrating.Wednesday, April 3, 13
The biggest joy in                    programming is knowing                      what you write does                     ...
We all want a peace of                      mind. Nirvana.Wednesday, April 3, 13
...but we’re all lazy asses.                         Trust me, I know. I am one too.Wednesday, April 3, 13
Most common excuses to                    not write tests                         Laziness: “Writing tests is such a chore...
What are the                         consequences?Wednesday, April 3, 13
96% of programmers do this to their                         computers at least once a week.                         (Okay,...
Shit programmers deal with                          Old code breaks when      Your code just broke other                  ...
Whose fault is it?              Yours, of course.Wednesday, April 3, 13
If you’re a true lazy                    programmer that doesn’t                    wanna deal with all that              ...
TDD & BDD                         Two jargons you should know                                since yesterdayWednesday, Apr...
Test Driven                    Development (TDD)                   “...the developer writes an (initially failing)        ...
Test Driven                    Development (TDD)                         Step 1: Write Test                         Step 2...
Problems with traditional TDD                         Test cases are written for the code -- not for the                  ...
Introducing                         Behavior Driven                          Development                         It’s just...
Behavior Driven                    Development (BDD)                   “...combines the general techniques and            ...
Behavior Driven                    Development (BDD)                         Step 1: Gather (and argue) requirements from ...
“With great power,                            comes great                          responsibility.”                       ...
You’re a web developer.                              You make websites.                         You’re Spiderman.         ...
4 Test Situations                          that we’ll be doing today                         Functional and module testing...
Best way to learn is by                    doing it yourself.                     So, lift your lazy ass and go clone this...
Need help? SHOUT!                            Or you can just talk to me at                         @conancat on Twitter, o...
Thanks for coming!                             Be a good Spiderman!Wednesday, April 3, 13
Upcoming SlideShare
Loading in...5
×

NodeJS: Writing tests -- A Beginners' Guide

8,786

Published on

This is an introductory slide for web development beginners about software testing, and how to write tests in NodeJS.

For more information, you can check out the project's page at http://conancat.github.com/node-test-examples/

Get the exercises and test project at this page: https://github.com/conancat/node-test-examples.

Need help? Buzz me on Twitter -- @conancat!

Published in: Technology
2 Comments
17 Likes
Statistics
Notes
No Downloads
Views
Total Views
8,786
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
88
Comments
2
Likes
17
Embeds 0
No embeds

No notes for slide

NodeJS: Writing tests -- A Beginners' Guide

  1. 1. NodeJS: Writing Tests A Beginners’ Guide Docs: http://conancat.github.com/node-test-examples/ Github: https://github.com/conancat/node-test-examples Prepared by Grey Ang @conancat | conancat@gmail.comWednesday, April 3, 13
  2. 2. Why write tests?Wednesday, April 3, 13
  3. 3. Programming should be funWednesday, April 3, 13
  4. 4. ...and not frustrating.Wednesday, April 3, 13
  5. 5. The biggest joy in programming is knowing what you write does what it intended to do, and it doesn’t break anything else.Wednesday, April 3, 13
  6. 6. We all want a peace of mind. Nirvana.Wednesday, April 3, 13
  7. 7. ...but we’re all lazy asses. Trust me, I know. I am one too.Wednesday, April 3, 13
  8. 8. Most common excuses to not write tests Laziness: “Writing tests is such a chore!” Perceived busyness: “We have too many things to do! We have other targets to hit!” Overconfidence: “This function is really easy. I can handle this.” Ego: “Come on, real men doesn’t need to test their code. It’ll definitely work. Trust me, I’m a programmer.”Wednesday, April 3, 13
  9. 9. What are the consequences?Wednesday, April 3, 13
  10. 10. 96% of programmers do this to their computers at least once a week. (Okay, I made up that number. But we all know how that feels.)Wednesday, April 3, 13
  11. 11. Shit programmers deal with Old code breaks when Your code just broke other you write new code people’s code Code that you wrote is You spend 8 hours slow as hell debugging your code and other people’s code What you’ve done is not what it supposed to do ...to name a few.Wednesday, April 3, 13
  12. 12. Whose fault is it? Yours, of course.Wednesday, April 3, 13
  13. 13. If you’re a true lazy programmer that doesn’t wanna deal with all that shit, write tests. Mark my words. You won’t regret it.Wednesday, April 3, 13
  14. 14. TDD & BDD Two jargons you should know since yesterdayWednesday, April 3, 13
  15. 15. Test Driven Development (TDD) “...the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards.” http://en.wikipedia.org/wiki/Test-driven_developmentWednesday, April 3, 13
  16. 16. Test Driven Development (TDD) Step 1: Write Test Step 2: Run the test. (It will fail, trust me. It’s okay. Take a deep breath. ) Step 3: Write the MINIMUM AMOUNT code to make the test pass Step 4: Test performance of code to optimal levels Step 5: Celebrate that your code works wonderfully Step 6: Write tests, rinse and repeat.Wednesday, April 3, 13
  17. 17. Problems with traditional TDD Test cases are written for the code -- not for the manager, client, or the users of the system. Code works with the test, code passes the test, but code FAIL with user behavior or client requirements. Traditional TDD is great for development. But if we want code that WORKS, we need to involve the people who spec the app. Remember, code is written for the benefit of people!Wednesday, April 3, 13
  18. 18. Introducing Behavior Driven Development It’s just like TDD, really. Only better.Wednesday, April 3, 13
  19. 19. Behavior Driven Development (BDD) “...combines the general techniques and principles of TDD with ideas from domain- driven design and object-oriented analysis and design to provide software developers and business analysts with shared tools and a shared process to collaborate on software development.” http://en.wikipedia.org/wiki/Behavior-driven_developmentWednesday, April 3, 13
  20. 20. Behavior Driven Development (BDD) Step 1: Gather (and argue) requirements from the business side or your users on what should be done Step 2: Write test cases to meet the pre-defined business requirements Step 3: Write the MINIMUM AMOUNT code to make the test pass Step 4: Show it to your business partner Step 5: ??? Step 6: Profit!Wednesday, April 3, 13
  21. 21. “With great power, comes great responsibility.” -- Uncle Ben, SpidermanWednesday, April 3, 13
  22. 22. You’re a web developer. You make websites. You’re Spiderman. Remember, you work with machines AND people. You write code for people.Wednesday, April 3, 13
  23. 23. 4 Test Situations that we’ll be doing today Functional and module testing Handling database calls Testing REST API layers Headless browser testingWednesday, April 3, 13
  24. 24. Best way to learn is by doing it yourself. So, lift your lazy ass and go clone this repo and start playing around. https://github.com/conancat/node-test-examplesWednesday, April 3, 13
  25. 25. Need help? SHOUT! Or you can just talk to me at @conancat on Twitter, or email me at conancat@gmail.com.Wednesday, April 3, 13
  26. 26. Thanks for coming! Be a good Spiderman!Wednesday, April 3, 13
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×