1

I'm working with a large project with 50,000 source files about 5000 tests spread over 2000 classes. These are mostly JUnit 3 with a smattering of JUnit 4. These tests are run on a frequent (daily or weekly) basis from batch files to ensure the product is working and not suffering from regressions or other issues.

I want to enumerate through the source or class files and produce a list of classes and methods that represent the test cases in the project. I can compare this list to determine which tests are not being run by the batch files.

Is there any simple way to do this such as functionality in JUnit? Or is there functionality in JUnit I could programatically drive to get it, e.g. to scan a dir full of class files and figure out which are tests. I realise that I could write code to individually load each class and start examining it for certain characteristics but if something exists I'd like to be able to use it.

The second part of the question, is there any commonly used way to to annotate tests? If I could annotate tests I could potentially filter them and generate batch files on the fly that run them according to the filter criteria. e.g. run all tests which need a network connection, run all tests that use subsystem A and so on.

Is there anything which would help me do this? I realise I could roll my own annotation with a comma separated list of values or something, but perhaps this sort of thing has been formalised and there are tools that work with it.

locka
  • 5,809
  • 3
  • 33
  • 38
  • This other question may help you with the second question: http://stackoverflow.com/questions/817135/grouping-junit-tests – Duncan Jones Nov 08 '12 at 14:26
  • Are you looking for some kind of Code Coverage tool, something like [Atlassian Clover](http://www.atlassian.com/software/clover/overview) – Jacob Schoen Nov 08 '12 at 14:26
  • Sounds like you might be looking for a build system too :-) Batch files to run "some" tests sounds a bit icky! – Duncan Jones Nov 08 '12 at 14:27
  • I'm not looking for code coverage, I'm looking for test coverage. People wrote tests, they added them to bat files to be run and scheduled jobs would run them on special machines. The problem is that as time goes on tests get commented out, or half implemented, or are broken and removed, or someone forgets to add a test back and I need to see how many tests we have total and how many are actually getting run. Anything not being run would have to be accounted for to decide why it isn't being run. – locka Nov 08 '12 at 14:33
  • Part of this exercise is to do away with batch files too. If I know all the tests and I implemented part 2 where I annotate them then in theory I could generate batch files (or ant or whatever) dynamically and there would be no bat files to maintain. – locka Nov 08 '12 at 14:36

1 Answers1

0

Tests are classes that extend TestCase (in case of JUnit 3) or annotated as @Test (in case of JUnit 4). So it is not a problem to do either using IDE or programmatically: write program that finds all *class files recursively into your classes folder(s) and tests whether class extends TestCase or is annotated with @Test.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • I'm aware I could do that but some tests don't directly extend TestCase. They might extend some other class which extends some other class which extends TestCase. And they might live in different packages which are not in the order I'm sequentially scanning a folder. Given that there could be quite a few of these sorts of edges it could save me a lot of time if there was code already out there which robustly did this. – locka Nov 08 '12 at 14:34