I have avoided writing tests for most of my projects through various means:
Testing is understandably a part of engineering that many dislike--there are so many different frameworks and libraries and it can feel like a time-suck.
But it's about time I really learned. Testing is an important skill to have in my tool belt. This is my attempt to teach myself how to incorporate tests into my code. Hopefully these notes are helpful for you as well. I'm going to make this a multi-part thing.
Blog contents for Part 1:
- Types of Testing
- Testing Tools for Unit Testing
In Part 2, I'll go over how to use them.
Unit tests focus on single methods or classes. These are your tests at the lowest level of your code.
They test one thing at a time and they don't do much else--no talking to a database, no communication across networks.
An example would be to call a method and check what it returns.
Integration tests check how different parts of the code work together--how well they integrate.
An example of this would be sending a POST request to a REST API and getting back a particular response.
This is sort of like test-driving a car. Instead of just making sure the engine works or the door works, you're testing the driving experience. End-to-end tests mimic users to see if the application is ready for the real-world.
Visual tests are pretty self explanatory--it's to see if any of your visuals have changed. Out of the four, this is the least important test mainly because changes are much more obvious here.
These are task automation managers that help you manage some housekeeping--they watch for file changes, perform build tasks and testing operations. I prefer Gulp, but they're both easy to pick-up.
Karma is run on Node and installed through NPM. Karma runs unit test It used to run unit tests client-side in real browsers. It provides the backbone that many other testing frameworks build off of.
Mocha provides many of the core testing functions needed for testing. Tools like
describe blocks, it statements, and basic assertions come from Mocha.
Alternatives: Jasmine, Jasmine-node for server-side, Vows, QUnit
An extension library designed to be used in conjunction with another testing
framework like Mocha or Jasmine. It gives you additional assertion capabilities
and lets you write your tests in a way that makes sense semantically.
Alternatives: Must, ShouldJS
Full-featured testing framework with assertions, spies, timers, etc.
In part 2, I'll talk about how to use these!