How are anti-aircraft missiles tested? How are anti-aircraft missiles and counter-measures tested?

When they design an anti-aircraft missile, how do they test it so that it actually locks on to a target and destroys it? Do they simply fly a plane in the air and then fire a missile at it and have the pilot eject?

Similarily, how are counter-measures tested? Do they fire a missile at a target and check whether it misses?
The short answer is that the final qualification tests are done against drones like the QF-4, which are converted from retired F-4 fighters.  These tests are still extremely expensive, into the millions per aircraft destroyed, so there are many dry runs and non-destructive tests completed beforehand.  Sacrificing a target drone isn't done until the project team is very confident of a positive result or they are unable to obtain necessary data by other means.