• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic