This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

junit 4 - test suite annotations

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JUnit 3.8, you could create your own suite dynamically be implementing a suite() method. In JUnit 4.0, you do something like:
@SuiteClasses( { A.class, B.class }).

Is there a way to build this list dynamically? (This may be more about annotations in which case, we can move it to Java In General.) I'd like to be able to build a test suite to include all the test classes it finds in the classpath excluding certain packages. In JUnit 3.8, I implemented this logic in the suite() method.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bumping this because it's been nine months and state of the art may have changed. That and the increased traffic due to the promotion this week.

Since I posted this in December, I learned that we can't pass a method to the annotation so it isn't possible in an annotation based way. I'm thinking one solution is to write a custom RunWith implementation. Any other ideas? Or comments on this approach.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne, a custom runner is "The" way to extend JUnit 4 in ways such as the one you describe. However, you should probably first look into whether Johannes Link's ClasspathSuite does the trick for you.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse,
Yes! That does what I need. Now just need to patiently wait until we can actually use Java 5.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you can also use the old suite()-Method style with JUnit 4 by using the AllTests runner.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lasse Koskela:
Jeanne, a custom runner is "The" way to extend JUnit 4 in ways such as the one you describe. However, you should probably first look into whether Johannes Link's ClasspathSuite does the trick for you.

It does now. It almost did what I needed - the only thing missing was the ability to include JUnit 3.X tests too and run a mix. Johannes included it in the latest version less than a week after I suggested it and provided a possible implementation.

ClasspathSuite is great! So is open source for that matter.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic