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 9176167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:02:48+00:00 2026-06-17T17:02:48+00:00

I was annoyed to find in the Parameterized documentation that when running a parameterized

  • 0

I was annoyed to find in the Parameterized documentation that “when running a parameterized test class, instances are created for the cross-product of the test methods and the test data elements.” This means that the constructor is run once for every single test, instead of before running all of the tests. I have an expensive operation (1-5 seconds) that I put in the constructor, and now the operation is repeated way too many times, slowing the whole test suite needlessly. The operation is only needed once to set the state for all of the tests. How can I run several tests with one instance of a parameterized 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-06-17T17:02:50+00:00Added an answer on June 17, 2026 at 5:02 pm

    I would move the expensive operation to a @BeforeClass method, which should execute just once for the entire parameterized test.

    A silly example is shown below:

    @RunWith(Parameterized.class)
    public class QuickTest {
    
      private static Object expensiveObject;  
      private final int value;
    
      @BeforeClass
      public static void before() {
        System.out.println("Before class!");
        expensiveObject = new String("Just joking!");
      }
    
    
      @Parameters
      public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][] { { 1 }, { 2 } });
      }      
    
      public QuickTest(int value) {
        this.value = value;
      }
    
      @Test
      public void test() {
        System.out.println(String.format("Ran test #%d.", value));
        System.out.println(expensiveObject);
      }
    }
    

    Will print:

    Before class!
    Ran test #1.
    Just joking!
    Ran test #2.
    Just joking!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just dealing with strings, and I find myself annoyed that strings can
Introduction I have been so annoyed by applications that have a startup dialog which
My manager is starting to get pretty annoyed that I'm devoting time to designing
I just right now migrated from C# to C++/CLR. First I was annoyed, that
I have developed a PDF Viewer by CGPDF*** methods. It's annoyed with waiting a
I'm annoyed that the I'm promised a fixed window that the user can't resize,
I'm really annoyed when using block tampered my pre-created object. I have this piece
This is a puzzle to me and I am really annoyed that I cannot
I have never been so annoyed with this wpf toolkit. The documentation is just
I have installed xcode on my mac but I am annoyed that I have

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.