Testing in Isolation with Unit Tests
In addition to allowing greater flexibility in simulating edge cases, unit tests have two other advantages: they run very quickly, since they don’t require any setup outside of Ruby (such as files, databases, and so on), and they force us to organize our code into small, testable units. Faster tests are good, since we can more quickly see the health of our app and more quickly and frequently run tests when writing new features and fixing bugs. Having small testable units is good, too, because it means our app will be easier to understand and maintain; instead of a big long block of code, we’ll have small units that do simple things, all glued together to form the app.
To run unit tests, we’ll need to break ...
Get Build Awesome Command-Line Applications in Ruby 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.