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! }

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.
  • dhenton

    what a lifesaver!!!! Thanks!!

  • Aleks

    yay, thanks!

  • Aleks

    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…

  • matz

    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

  • Krovi

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

  • http://dobrzanski.net Jaroslaw Dobrzanski

    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 ;)

  • http://dobrzanski.net Jaroslaw Dobrzanski

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

  • Eric

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

  • Steve Buroff

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

  • Glader

    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.

  • Renato

    Thanks!!! you’ve made my day.

  • Vasanth

    bingo. Thanks.

  • Peter Osipov

    Indeed, useful! Thanks.

    Jaroslaw Dobrzanski

    Thanks for the explanation regarding the comment.

  • Peter Osipov

    Indeed, useful! Thanks.

    Jaroslaw Dobrzanski

    Thanks for the explanation regarding the comment.

  • Peter Osipov

    Indeed, useful! Thanks.

    Jaroslaw Dobrzanski

    Thanks for the explanation regarding the comment.

  • p47l4f0n

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

  • foobar

    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.

  • deadbeef

    Finally working code. I was stuck on things like

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

  • http://icaro.blogspot.com Icaro

    Very Usefull

    Thx

  • enietom

    Thanks a lot man!

  • Zen

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

  • http://www.testing-associates.com rastogis

    nice write up.

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

  • cris

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

  • http://www.rossgroupinc.com Al

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

  • Nobody

    Thank you, my master:)

  • Aluink

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

  • matt

    Mahalo!

  • Kk

    i m thankful