This answer works if you don't mind having extra collateral to remember/set the CLASSPATH
: How to run JUnit test cases from the command line. But, if the project was created by Netbeans, the classpath is already in your project, and the project 'knows' how to run single unit tests and single unit test methods.
$ ant -p
. . .
test-single Run single unit test.
test-single-method Run single unit test.
. . .
However, if you try to build these targets, you will be presented with this error message (and then others) with no guidance on how to set the properties in question:
BUILD FAILED
/home/me/myproject/nbproject/build-impl.xml:1300: Must select some files in the IDE or set javac.includes
Set the properties incorrectly, and ant will simply tell you that the build succeeded, but not compile nor run your test. This is harder than it should be.
So, how do we set the properties that these targets require?