JUnit 4 TestSuite Declaration

This is mainly for my own reference but if it helps people out there great!  The documentation on this aspect of JUnit is very poor.

package agalliao.wealthManagment.domain;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
investmentTests.class,
catalogTests.class,
markerTests.class
})
public class AllTests {
// why on earth I need this class, I have no idea!
}

Related Articles:

    Post Footer automatically generated by Add Post Footer Plugin for wordpress.

    About Joe Ocampo

    My personal philosophy is simple: "Have a good strategy that sets the environment for success through the enablement of the whole. Be agile but with a mind towards pragmatism. Delegate to the best qualified individuals, but don’t be afraid to involve yourself in all parts of a job. Treat everyone with respect, humility, and with a genuine pursuit towards excellence." Respected business and technical leader with expertise in directing organization towards effective results driven outcomes. Proven ability to perform and communicate from both technical and business perspectives. Strong technical and business acumen developed through experience, education and training. Provides the ability to utilize technology, harness business intelligence and execute strategically by optimizing systems, tools and process. Passionate about building people, companies and software by containing cost, maximizing operational throughput and capitalize on revenue. Looks to leverage the strengths of individuals and grow the organization to their maximum potential by harnessing the power of their collective whole and deliver results. Co-Founder of LosTechies.com
    This entry was posted in Java, JUnit. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

    28 Responses to JUnit 4 TestSuite Declaration

    1. dhenton says:

      what a lifesaver!!!! Thanks!!

    2. Aleks says:

      yay, thanks!

    3. Aleks says:

      re “why on earth I need this class, I have no idea! “, you may have tierUp/Down methods or whatever in that class like I have. For example if you need to prepare database or a container…

    4. matz says:

      Thanks!!!!

      Re: “Why on earth …”
      I think, something is needed that can be annotated.
      see
      http://junit.org/junit/javadoc/4.5/org/junit/runner/RunWith.html

    5. Krovi says:

      Thanks Joe, that was really helpful (right on top in google search results)

    6. re “why on earth I need this class, I have no idea! ” (apart from what Aleks wrote)…
      You need that declaration in order to keep this class definition in a way that compiles ;)

    7. Anyway, thanks for a publishing that tip! You saved my time :)

    8. Eric says:

      ty a lot!! This is what I was looking for!!

    9. Steve Buroff says:

      Thanks very much. I really needed this.
      AND, the junit documentation should be updated with something
      like what you provided.

    10. Glader says:

      I’m nearly in tears it’s so beatiful. I have been looking for a way to create good looking test suites in java for over 6 hours now and then I find this.

      thank you very much, you have done everyone a huge favor.

    11. Renato says:

      Thanks!!! you’ve made my day.

    12. Vasanth says:

      bingo. Thanks.

    13. Peter Osipov says:

      Indeed, useful! Thanks.

      Jaroslaw Dobrzanski

      Thanks for the explanation regarding the comment.

    14. Peter Osipov says:

      Indeed, useful! Thanks.

      Jaroslaw Dobrzanski

      Thanks for the explanation regarding the comment.

    15. Peter Osipov says:

      Indeed, useful! Thanks.

      Jaroslaw Dobrzanski

      Thanks for the explanation regarding the comment.

    16. p47l4f0n says:

      Hi, thank you too. This is really missing on the Internet :)

    17. foobar says:

      The class is needed so that you can add @BeforeClass methods that initialize all other test cases in this suite. It breaks independence but it’s a life saver when you need it.

    18. deadbeef says:

      Finally working code. I was stuck on things like

      TestSuite suite = new TestSuite(“Test for tests”);
      suite.add(NOTHING WORKS AAAHHHHH);

    19. Icaro says:

      Very Usefull

      Thx

    20. enietom says:

      Thanks a lot man!

    21. Zen says:

      thank you. just what I was looking for. saved hours of research.

    22. rastogis says:

      nice write up.

      Consultants available for Software testing, Test Management requirements. reach us at Testing-Associates

    23. cris says:

      Thank you very much! You’re right, there’s no documentation for this.

    24. Al says:

      I’ll add my voice to the thank yous. Short and sweet.

    25. Nobody says:

      Thank you, my master:)

    26. Aluink says:

      This is all cool and all, but how do you run it? I’m using eclipse, but the IDE isn’t key.

    27. matt says:

      Mahalo!

    28. Kk says:

      i m thankful