If you're buying a second-hand DSLR camera (or you just want to check the sensor of your current camera), CNET suggests a neat trick to identify dust or dead pixels: point it at the sky and take a photo.
Photo by merala
It's a clever way to avoid potential problems:
A good way to check for sensor issues is to shoot into a bright subject (such as blue sky) or a white wall with adequate light and the lens stopped down to its minimum aperture, say f/22. Observing the resulting image on a computer or the screen at full magnification will show if there are any obvious issues like dust that need resolving.
Dead or hot pixels on the sensor can also be identified using this method, though you might also want to shoot a totally dark subject (such as take a photo with the lens cap attached) to compare with the bright image for verification purposes.
Dust is something that can usually be cleaned, but scratches or dead pixels will be a deal-breaker. Similarly, when buying a used lens, you should first check the mount. Click the link for more tips on buying a second-hand camera.
How To Buy A Used DSLR [CNET]