Headphones should be allowed while taking a test. As long as you know the person is not looking up answers, or using it somehow to cheat there is no reason it should not be allowed. Some people get nervous when testing and listening to music, or using headphones to drown out background music will help them.
Headphones should not be allowed while taking a test. This is because the test-taker could easily listen to a recording that contains the answers of the test. This would defeat the purpose of the test itself, and would cause detriment. There are also little reasons to consider of why someone would ever use headphones during a test in the first place.