Disconnect all external devices except keyboard, mouse, display, Ethernet connection (if applicable), and connection to AC power. Apple Hardware Test might display an error message if you don't disconnect all other devices.
Make sure that your Mac is on a hard, flat, stable, well-ventilated work surface.
Shut down your Mac.
Turn on your Mac, then immediately press and hold the D key on your keyboard. Keep holding the D key until you see the Apple Hardware Test icon:
Select your language and click the right arrow. If you aren't using a mouse, you can use the up and down arrows to select a language, then press the Return key.
To begin testing, click the Test button, press T, or press Return. Optionally select "Perform extended testing" before beginning the test. This performs a more thorough test that takes longer to complete.
When the test is complete, review your test results in the lower-right section of the window.
To quit Apple Hardware Test, click Restart or Shut Down at the bottom of the window.
Some Mac computers that shipped with OS X Lion v10.7 or later will start up from AHT over the Internet if your startup disk doesn't contain AHT, or if you hold down Option-D at startup. This requires an Internet connection over Ethernet or Wi-Fi.
If you're using OS X Lion v10.7 or earlier and you can't get AHT to start, see if you have an OS X installation disc named “Applications Install Disc 2.” Insert the disc in your internal optical drive or external Apple SuperDrive before following the steps above. Or, if you're using a MacBook Air (Late 2010), plug the MacBook Air Software Reinstall thumb drive into your USB port instead.