Teaching to the test refers to teaching students specific information needed to pass a standardized test; this usually means failing to teach them information in a wider context.
Teaching to the test is a hard thing to avoid. Many modern tests are designed to test all aspects of a subject that are important; most curricula are designed to teach all aspects of a subject that are important. If there isn't a tremendous amount of overlap, something has gone wrong.
Moreover, you often can't use simple metrics like "teaching to the test is a problem when you change what you teach because of your expectations of what will be required for the test" -- you should be able to use this metric, but usually the people telling you what to teach are the same people organizing, and often writing, the test. You have to change what you teach based on their direction, even if that walks in lockstep with what is on the test.
The American school system has attempted to solve this by simply putting all the educational expectations down on paper, and then testing for all of it (particularly in math and English language arts; not so much in science). This has caused some problems. Testing has become a fairly intense undertaking from third grade on up. Moreover, as everything becomes not only recommended, but required, teachers have had to up their game, making lesson plans that cover as much as possible as thoroughly as possible, from kindergarten on up... but without an increase in planning time.
The de facto result is that the current sin in American schools is not so much teaching to the test, but 'teaching the test' -- taking sample tests put out by many states, and using them as review for a few weeks before the actual test. Of course, this is actually what the sample tests are intended for, more or less -- to give the students a chance to see the format and practice their test-taking skills before the actual test. Identifying the grey area where the system is being abused it difficult, and sometimes impossible. So the debate continues...