How do I run CiviCRM PHPUnit tests from within Netbeans?
[This all assumes you have civicrm-buildkit already working and that you can run CiviCRM phpunit tests successfully from the command line.]

1. Tell Netbeans which phpunit executable you're using.


Go to Tools » Options, then PHP tab, PHPUnit subtab.
Set the path of your PHPUnit script.  See screenshot:




2. Create a shell script with your environment variable.

Copy this script into a file anywhere on your filesystem:

#!/bin/sh
env CIVICRM_UF=UnitTests /path/to/your/phpunit5 $@


3. Tell Netbeans where to find your tests.


Go to File menu » Project Properties, Testing tab.
Click Add Folder and select the &lt;civiroot&gt;/tests/phpunit folder.  See screenshot:




4. Tell Netbeans the CiviCRM-specific info it needs.


Go to File menu » Project Properties, PHPUnit tab.
Check the Use XML Configuration box.
Set the XML Configuration path to &lt;civiroot&gt;/phpunit.xml.dist.
Check the Use Custom PHPUnit Script box.
Set the PHPUnit Script to the path of the file from step 2.




5. You're ready to go!

From any PHP file in the main codebase, press Ctrl-F6 (or Run menu » Test File) to start your tests.  You can also re-run only failed tests.

Troubleshooting

If PHPUnit isn't working, bring up the "Output" window (Window menu » Output).  This will show you the exact command Netbeans tried to run.  You can run it on your command line to compare results and tweak it.