Testing on the Toilet

April 25, 2007

Refactoring Tests in the Red With a good set of tests in place, refactoring code is much easier, as you can quickly gain a lot of confidence by running the tests again and making sure the code still passes. As suites of tests grow, it's common to see duplication emerge. Like any code, tests should ideally be kept in a state that's easy to understand and maintain. So, you'll want to refactor your tests, too. However, refactoring tests can be hard because you don't have tests for the tests. How do you know that your refactoring of the tests was safe and you didn't accidentally remove one of the assertions? If you intentionally break the code under test, the failing test can show you that your assertions are still working. For example, if you were refactoring methods in CombineHarvesterTest, you would alter CombineHarvester, making it return the wrong results. Check that the reason the tests are failing is because the assertions are failing as you'd expect them to. You can then (carefully) refactor the failing tests. If at any step they start passing, it immediately lets you know that the test is broken – undo! When you're done, remember to fix the code under test and make sure the tests pass again. (revert is your friend, but don't revert the tests!) Let's repeat that important point: When you're done... remember to fix the code under test!

Summary

Refactor production code with the tests passing:

This helps you determine that the production code still does what it is meant to.

Refactor test code with the tests failing:

This helps you determine that the test code still does what it is meant to.

More information, feedback, and discussion: http://googletesting.blogspot.com Copyright © 2007 Google, Inc. Licensed under a Creative Commons Attribution–ShareAlike 2.5 License (http://creativecommons.org/licenses/by-sa/2.5/).

Refactoring Tests in the Red

Apr 25, 2007 - With a good set of tests in place, refactoring code is much easier, as you can quickly gain a lot of confidence by running the tests again and ...

140KB Sizes 1 Downloads 196 Views

Recommend Documents

Simulating Time in jsUnit Tests
Oct 2, 2008 - Sometimes you need to test client-side JavaScript code that uses setTimeout() to do some work in the future. jsUnit contains the Clock.tick() method, which simulates time passing without causing the test to sleep. For example, this func

Simulating Time in jsUnit Tests
Oct 2, 2008 - Sometimes you need to test client-side JavaScript code that uses ... Clock.reset(); // Clear any existing timeout functions on the event queue.

Frame-Based Behavior Preservation in Refactoring
Department of Computer Science, Tokyo Institute of Technology, Japan, ... Graduate School of Information Science, Nara Institute of Science and Technology, ...

Weak Instrument Robust Tests in GMM and the New Keynesian ...
Journal of Business & Economic Statistics, July 2009. Cogley, T., Primiceri ... Faust, J., and Wright, J. H. (2009), “Comparing Greenbook and Reduced Form. Forecasts Using a .... frequency of price adjustment for various goods and services.

Tests with Correct Size in the Simultaneous Equations ...
Tests with Correct Size in the Simultaneous. Equations Model. Copyright 2002 by. Marcelo Jovita Moreira. Page 2. 1. Abstract. Tests with Correct Size in the ...

Weak Instrument Robust Tests in GMM and the New Keynesian ...
Lessons From Single-Equation Econometric Estimation,” Federal Reserve. Bank of ... 212) recognized a “small sam- ... Journal of Business & Economic Statistics.

Weak Instrument Robust Tests in GMM and the New Keynesian ...
We discuss weak instrument robust statistics in GMM for testing hypotheses on the full parameter vec- tor or on subsets of the parameters. We use these test procedures to reexamine the evidence on the new. Keynesian Phillips curve model. We find that

Download REFACTORING DATABASES ...
From the Back Cover Refactoring has proven its value in a wide range of development projects–helping software professionals improve system designs, ...

Nonparametric Tests of the Markov Hypothesis in Continuous-Time ...
Dec 14, 2010 - Princeton University and NBER, Princeton University and University of .... Under time-homogeneity of the process X, the Markov hypothesis can ...