2. Unit Testing, Node.JS style
What is unit testing
“What to test”, not “how to test”
Vows, NodeMock, and CommonSense™
3. Vows
Use vows properly
Run the test suite runner BEFORE pull requests
Check confessions server AFTER pull request
integration
4. Test Suite Runner
$ bin/fo test
$ bin/fo test -v (verbose)
$ bin/fo --help (kills nyancats)
Test it out...
5. Writing a test case
Config Object
Goal:
Load contents from a config file
Parse contents and return as a JSON string
Should handle errors gracefully
See wiki/testing-example1-basic
6. Writing a test case
What’s the problem here?
1 - Depends on files
2 - Hard to setup test environment
3 - It’s NOT unit testing
9. NodeMock
Mocking objects in test cases are messy
How to re-use mock objects
When to re-use mock objects
When NOT to re-use mock objects
10. Fixtures
Control environment
“Clean Slate” to run tests on
No external dependencies
Injects dependencies
Used in manufacturing’s testing procedures
See wiki/testing-example4-fixtures
11. Dependency Injection
WTF is DI?
Inject dependency vs Encapsulated dependency
Constructor injection, Getter/setter injection,
Service Locator, Factory & DI Containers
Dependency Injection = Easier to test
Use FO(‘...’) to auto-construct components