Wanting to run a single method in a test class TestMyClass is propably sign of poor design of the tests, but can it be done from the commandline without using Ant ?
Normally when I run JUnit tests explicitly, I do:
I would like to only run a single specific @Test annotated method from TestMyClass.
One way would be to create a subclass of the BlockJUnit4ClassRunner and override the protected computeTestMethods() to return only the method(s) that you want to run, for instance the ones for which you specified a method name as a system property on the commandline (-D option). Though there must be another (simpler) way. I know the Eclipse test runner can run individual test methods. I wonder how they've implemented it.
Edit: The old junit.textui.TestRunner utility provides a way to run a single method on the command-line, via the runSingleMethod(), but it doesn't support JUnit4 annotated test classes.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
subject: Running single method in test class with JUnit 4 from commandline without using Ant.