Mock Object Strategies

By Eric — 12 minute read

How do you get your production code to use real objects and your test code to use mock objects?

Here's the class we want to test (adapted from Object-Oriented Design Heuristics, Arthur J. Riel):

public class HeatFlowRegulator 
{ 
    private Furnace furnace; 
    private Set house;    

    public HeatFlowRegulator(Set house) 
    { 
        this.house = house …

Read more...

Testing Styles: Favor Unit Testing

By Eric — 8 minute read

Ideally, human efforts in testing should focus on building tests -- figuring out the strategies, test cases, and test data. From there, we'd rather let the computer run the tests and verify the results. If you had to test everything manually every day, you would either not do it, or really …

Read more...

Why Exceptions Are Better Than Returned Error Codes

By Eric — 3 minute read

I'm occasionally surprised that some programmers prefer an error handling system of returned error codes over exceptions. After spending several years with both approaches, I've become convinced that exceptions are a superior model. If you agree, great! If not, read on and let me try to persuade you. I'm always …

Read more...