Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:47:40+00:00 2026-05-16T10:47:40+00:00

I have 2 files: xxxxxTest.java [ refer this ] public class xxxxxTest extends TestCase

  • 0

I have 2 files:

xxxxxTest.java
[refer this]

public class xxxxxTest extends TestCase {

    // Run setup only once
    public static Test suite() {
        TestSetup setup = new TestSetup(new TestSuite(xxxxxTest.class)) {
            protected void setUp() throws Exception {
              //Some init which i need only once
            }

            protected void tearDown() throws Exception {

            }
        };
        return setup;
    }

    public void testMyFirstMethodTest() {
        assertNotNull(do stuff here);
    }
}

AllTests.java

public class AllTests {
    public static Test suite() {
        TestSuite suite = new TestSuite("Test for xxxxxx");
        //$JUnit-BEGIN$
        suite.addTestSuite(xxxxxTest.class);
        //$JUnit-END$
        return suite;
    }
}

So, my individual test(xxxxxTest.java) works fine, exactly as I want.When i run my test suite (AllTests.java), it fails, because the init in setup() i provided in xxxxxTest.java are not being executed.

Any suggestions?

UPDATE

I tried @BeforeClass in JUnit 4. But, it didn’t help because in my ssetUp() method, I start an embedded Jetty server (server.start()), the server works fine with the code I posted, but when I do the same with @BeforeClass, it does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:47:41+00:00Added an answer on May 16, 2026 at 10:47 am

    In rare cases I also hacked around with static when using JUnit3.

    In your case:

    • give the static{} initializer a try, maybe it works opposed to your static initialization.
    • if possible upgrade to JUnit4 and use @BeforeClass annotation (it is run once for a test-class). Your other JUnit3 test-classes should be runnable with JUnit4 test-runner also.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a directory with around 1000 files....i want to run a same code
I have files named xxx.java.i , xxx.java.d , xxx.jar.i . I know that these
I have been publishing my MVC3 project to IIS including All Project Files, this
I have files which is something like : dslkj20111104-BATCH2244_20111113-091347.txt I only need dslkj and
I would like to have files named for example: dd.mm.yyyy.log How is this possible
I have files and directories setup on a Windows network share (\foo). I want
I have files that I want only 'foo' and 'bar' left from split. dn
I would like to create a tar archive in Java. I have files which
I have files with texts an constants. How can I get constant name and
I have files served like so: AJAX request handler -> Include file I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.