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

  • SEARCH
  • Home
  • 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 503087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:21:29+00:00 2026-05-13T06:21:29+00:00

When using this approach below, by setting up the jUnit with Suites. We got

  • 0

When using this approach below, by setting up the jUnit with Suites. We got the problem when all @BeforeClass in every Testclass will be executed before any tests starts to execute.
(For each n TestClass file the @BeforeClass runs, then after they have execute, it started to execute the first MyTest.class files @Test)

This will cause that we allocate up much resources and memory.
My thoughts was that it must be wrong, shouldn’t each @BeforeClass run only before the actual testclass is executed, not when the Suite is started?

@RunWith(Suite.class)
@Suite.SuiteClasses({ MyTests.class, Mytests2.class, n1, n2, n })
public class AllTests {
    // empty
}


public class MyTests {  // no extends here
    @BeforeClass
    public static void setUpOnce() throws InterruptedException {
        ...
    @Test
        ...

public class MyTests2 {  // no extends here
    @BeforeClass
    public static void setUpOnce() throws InterruptedException {
        ...
    @Test
        ...
  • 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-13T06:21:30+00:00Added an answer on May 13, 2026 at 6:21 am

    Write a @BeforeClass method in the AllTests class which will be executed when the suite is started.

    public class MyTests1 { 
        @BeforeClass
        public static void beforeClass() {
            System.out.println("MyTests1.beforeClass");
        }
    
        @Before
        public void before() {
            System.out.println("MyTests1.before");
        }
    
        @AfterClass
        public static void afterClass() {
            System.out.println("MyTests1.AfterClass");
        }
    
        @After
        public void after() {
            System.out.println("MyTests1.after");
        }
    
        @Test
        public void test1() {
            System.out.println("MyTests1.test1");
        }
    
        @Test
        public void test2() {
            System.out.println("MyTests1.test2");
        }
    }
    
    
    
    public class MyTests2 { 
        @BeforeClass
        public static void beforeClass() {
            System.out.println("MyTests2.beforeClass");
        }
    
        @Before
        public void before() {
            System.out.println("MyTests2.before");
        }
    
        @AfterClass
        public static void afterClass() {
            System.out.println("MyTests2.AfterClass");
        }
    
        @After
        public void after() {
            System.out.println("MyTests2.after");
        }
    
        @Test
        public void test1() {
            System.out.println("MyTests2.test1");
        }
    
        @Test
        public void test2() {
            System.out.println("MyTests2.test2");
        }
    }
    
    
    
    
    @RunWith(Suite.class)
    @Suite.SuiteClasses( { MyTests1.class, MyTests2.class })
    public class AllTests {
    
        @BeforeClass
        public static void beforeClass() {
            System.out.println("AllTests.beforeClass");
        }
    
        @Before
        public void before() {
            System.out.println("AllTests.before");
        }
    
        @AfterClass
        public static void afterClass() {
            System.out.println("AllTests.AfterClass");
        }
    
        @After
        public void after() {
            System.out.println("AllTests.after");
        }
    
        @Test
        public void test1() {
            System.out.println("AllTests.test1");
        }
    
        @Test
        public void test2() {
            System.out.println("AllTests.test2");
        }
        
    }
    

    Output:

    AllTests.beforeClass
    MyTests1.beforeClass
    MyTests1.before
    MyTests1.test1
    MyTests1.after
    MyTests1.before
    MyTests1.test2
    MyTests1.after
    MyTests1.AfterClass
    MyTests2.beforeClass
    MyTests2.before
    MyTests2.test1
    MyTests2.after
    MyTests2.before
    MyTests2.test2
    MyTests2.after
    MyTests2.AfterClass
    AllTests.AfterClass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Django CMS is a good suggestion, it depends on how… May 14, 2026 at 7:12 pm
  • Editorial Team
    Editorial Team added an answer From what I can tell, LHND is not even a… May 14, 2026 at 7:12 pm
  • Editorial Team
    Editorial Team added an answer The EJB specification don't specify how clustering should be achieved,… May 14, 2026 at 7:12 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.