Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tim McMurry
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic