aspose file tools*
The moose likes Beginning Java and the fly likes Running single method in test class with JUnit 4 from commandline without using Ant. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Running single method in test class with JUnit 4 from commandline without using Ant." Watch "Running single method in test class with JUnit 4 from commandline without using Ant." New topic
Author

Running single method in test class with JUnit 4 from commandline without using Ant.

Tim McMurry
Greenhorn

Joined: Oct 31, 2009
Posts: 22
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.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running single method in test class with JUnit 4 from commandline without using Ant.