While portable computers, like MacBook and MacBook Pro, can normally be used with external peripherals attached (like a keyboard, mouse, external display, and so forth), you shouldn't have any external peripherals attached while running Apple Hardware Test. For best results, run Apple Hardware Test on your MacBook Pro without any accessories connected except for the power adapter.
MacBook and MacBook Pro: Using Apple Hardware Test
Apple Hardware Test is a comprehensive suite of test utilities, designed for advanced troubleshooting of hardware issues on Macintosh computers. It's provided on bootable optical media and used by holding down the "D" key while the MacBook Pro starts up.