How do I programmatically run all the JUnit tests in my Java application?
Posted
by Andrew McKinlay
on Stack Overflow
See other posts from Stack Overflow
or by Andrew McKinlay
Published on 2010-03-09T19:29:53Z
Indexed on
2010/03/13
7:45 UTC
Read the original article
Hit count: 227
From Eclipse I can easily run all the JUnit tests in my application.
I would like to be able to run the tests on target systems from the application jar, without Eclipse (or Ant or Maven or any other development tool).
I can see how to run a specific test or suite from the command line.
I could manually create a suite listing all the tests in my application, but that seems error prone - I'm sure at some point I'll create a test and forget to add it to the suite.
The Eclipse JUnit plugin has a wizard to create a test suite, but for some reason it doesn't "see" my test classes. It may be looking for JUnit 3 tests, not JUnit 4 annotated tests.
I could write a tool that would automatically create the suite by scanning the source files.
Or I could write code so the application would scan it's own jar file for tests (either by naming convention or by looking for the @Test annotation).
It seems like there should be an easier way. What am I missing?
© Stack Overflow or respective owner