2

We have a policy that all test classes extend a given test class. The base class sets the JUnit runner to use as well as checking other things about the test class, so not subclassing from it means that other things you're doing wrong aren't going to be checked. (The most serious of these is when there is a category indicating that a test is expensive to run, but because the runner isn't being used, the test will run even for the run-fast-tests build target.)

I figure this is going to involve parsing the Java code, but I can only seem to find parsers for class files. Is there a good parser out there somewhere for parsing Java source?

(This could tie into another question I was going to ask about enforcing use of certain Javadoc tags, since such a parser would surely also parse Javadoc.)

Alternatively is there a DRY way to set a JUnit runner without subclassing? The whole subclassing business is really, really inconvenient.

Hakanai
  • 12,010
  • 10
  • 62
  • 132
  • 1
    I think that's a bad policy. This is what annotations and groups are for. Have a look at TestNG. – duffymo Dec 18 '12 at 23:58
  • Why would this involve parsing source? http://stackoverflow.com/questions/492184/how-do-you-find-all-subclasses-of-a-given-class-in-java (And what duffymo said.) – Dave Newton Dec 18 '12 at 23:58
  • (1) I'm not using TestNG so it won't really help me. (2) We're already using annotations, and the base test class is setting the runner which has the code for adhering to those annotations, since JUnit has no alternative. – Hakanai Dec 19 '12 at 00:03
  • Which version of JUnit are you using? – Patricia Shanahan Dec 19 '12 at 00:19
  • Version 4.9 (latest afaik) – Hakanai Dec 19 '12 at 00:44

0 Answers0