How to run Apple Hardware Test with broken keyboard?
You can try to run the AHT from a USB drive.

see the above link to find/download the AHT for your model.


  1) Download the AHT for your computer (see downloads below for
  specific models).
  
  1b) My copy had me convert the downloaded .dmg from some “old” type
  using Disk Utility. (Just open the .dmg in Disk Utility and “Convert”
  to a new target, then mount the target.)
  
  2) Mount and completely wipe a USB stick.
  
  3) From the AHT image, copy /System to the root folder of your USB
  stick:
  
  cd /Volumes/USB_STICK/ &amp;&amp; cp -r ~/AHT_ARCHIVE/System .
  
  4) Now, from the USB drive, copy the
  /System/Library/CoreServices/.diagnostics/diags.efi to the root
  directory:
  
  cd /Volumes/USB_STICK/ &amp;&amp; cp
  ./System/Library/CoreServices/.diagnostics/diags.efi .
  
  5) Shutdown all applications.
  
  6) “bless” the USB drive in mount-mode, with the EFI file, and
  immediately reboot:
  
  cd /Volumes/USB_STICK/ &amp;&amp; sudo bless --mount /Volumes/USB_STICK
  --setBoot --file diags.efi &amp;&amp; sudo reboot
  
  7) You should now be booting into AHT -- don’t hold down any keys.
  
  8) Run the tests, and yank the USB key after AHT reboots you.