Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Unit Testingthe regression shield
Unit Testing, Node.JS styleWhat is unit testing“What to test”, not “how to test”Vows, NodeMock, and CommonSense™
VowsUse vows properlyRun the test suite runner BEFORE pull requestsCheck confessions server AFTER pull requestintegration
Test Suite Runner$ bin/fo test$ bin/fo test -v (verbose)$ bin/fo --help (kills nyancats)Test it out...
Writing a test caseConfig ObjectGoal: Load contents from a config file Parse contents and return as a JSON string Should hand...
Writing a test caseWhat’s the problem here? 1 - Depends on files 2 - Hard to setup test environment 3 - It’s NOT unit testing
MocksControl EnvironmentRun It Anywhere™Mock objects to the rescue!See wiki/testing-example2-mock
NodeMockhttps://github.com/arunoda/nodemockMocking solution made easyNo need to rewrite code for every single testcontextS...
NodeMockMocking objects in test cases are messyHow to re-use mock objectsWhen to re-use mock objectsWhen NOT to re-use moc...
FixturesControl environment“Clean Slate” to run tests onNo external dependenciesInjects dependenciesUsed in manufacturing’...
Dependency InjectionWTF is DI?Inject dependency vs Encapsulated dependencyConstructor injection, Getter/setter injection,S...
Code SamplesConfig File: http://pastebin.com/N65mt2ehSimple Test: http://pastebin.com/Df7ysdEHJSON File: http://pastebin.co...
-Q&A-
Upcoming SlideShare
Loading in …5
×

Unit testing for 40 square software

1,131 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Unit testing for 40 square software

  1. 1. Unit Testingthe regression shield
  2. 2. Unit Testing, Node.JS styleWhat is unit testing“What to test”, not “how to test”Vows, NodeMock, and CommonSense™
  3. 3. VowsUse vows properlyRun the test suite runner BEFORE pull requestsCheck confessions server AFTER pull requestintegration
  4. 4. Test Suite Runner$ bin/fo test$ bin/fo test -v (verbose)$ bin/fo --help (kills nyancats)Test it out...
  5. 5. Writing a test caseConfig ObjectGoal: Load contents from a config file Parse contents and return as a JSON string Should handle errors gracefullySee wiki/testing-example1-basic
  6. 6. Writing a test caseWhat’s the problem here? 1 - Depends on files 2 - Hard to setup test environment 3 - It’s NOT unit testing
  7. 7. MocksControl EnvironmentRun It Anywhere™Mock objects to the rescue!See wiki/testing-example2-mock
  8. 8. NodeMockhttps://github.com/arunoda/nodemockMocking solution made easyNo need to rewrite code for every single testcontextSee wiki/testing-example3-nodemock
  9. 9. NodeMockMocking objects in test cases are messyHow to re-use mock objectsWhen to re-use mock objectsWhen NOT to re-use mock objects
  10. 10. FixturesControl environment“Clean Slate” to run tests onNo external dependenciesInjects dependenciesUsed in manufacturing’s testing proceduresSee wiki/testing-example4-fixtures
  11. 11. Dependency InjectionWTF is DI?Inject dependency vs Encapsulated dependencyConstructor injection, Getter/setter injection,Service Locator, Factory & DI ContainersDependency Injection = Easier to testUse FO(‘...’) to auto-construct components
  12. 12. Code SamplesConfig File: http://pastebin.com/N65mt2ehSimple Test: http://pastebin.com/Df7ysdEHJSON File: http://pastebin.com/Qbt52CbaWith Mock: http://pastebin.com/G0812kxzNodeMock: http://pastebin.com/swGR379hFixture: http://pastebin.com/f4daFf5Z
  13. 13. -Q&A-

×