Unless you have a Mac released after July 20, 2011, Lion removes the ability to hold 'D' at startup to boot into Apple hardware test. Apple now recommends you simply use the disks that came with your Mac. Fortunately, it's an easy feature to restore.
First, you need an install disk. You have a couple of options:
Use the install disk that came with you Mac. Note this may be the 'Applications' Disk, and not the primary install disk. To find out which it is for your model go here.
NOTE: It's best if you use the install discs specific to each Mac you have to guarantee AHT will work.
Or you an use a Snow Leopard install disk. For this to work your Mac model will need to be older than that install disk, that's when it was introduced, not when you bought it. If it's an original Snow Leopard disk, that's older than Oct 2009, or if it's a more recent one, older than 10.6.3. If your Mac is old enough, you may even have success with a Leopard install disk.
In any event, try to use the most recent disk that would work with your computer. If you're not sure if a disk will work for you, try the hint anyway, it won't harm your computer.
So, insert your install disk and open Terminal. Type:
Mac OS X Hints