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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:12:11+00:00 2026-06-11T12:12:11+00:00

I wrote a long parameterized test, one of whose parameters is a constructor call

  • 0

I wrote a long parameterized test, one of whose parameters is a constructor call with double-brace syntax to construct a different object for each row of the 2D array:

Object[][] data = new Object[][] {
{ 1, 2, 3, new Blah() {{ setA(); }} }
{ 1, 2, 3, new Blah() {{ setB(); }} }
...

Since the philosophy of JUnit is to call the test case constructor on each @Test, I was assuming that it would do the same with parameterized tests – but I’m seeing that it’s only calling that constructor (the constructor defined for the parameterized test) once per row, not once per test per row.

So, the test fields are behaving globally and tests are affecting each other. I want to know if there’s a way to force the runner to call the constructor for each tests, as with the regular JUnit runner. Google and the JUnit pages are not helping me on this case. I’d really rather not rewrite the entire test, which is extensive and fairly readable at this point.

  • 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-11T12:12:12+00:00Added an answer on June 11, 2026 at 12:12 pm

    I’m not sure if I completely follow you but when the test is run, this is what happens:

    1. The method you’ve annotated with @Parameters method is called once and only once.
    2. A test runner instance is created for each row in the collection returned by the annotated method.
    3. The test is instantiated for each row in the parameter collection using its constructor, but it is passed in the corresponding parameter value row that was cached from the initial invocation.

    You can see where this happens by clicking here and here. If you’re mutating state between calls (using a static method or whatever) expect to see weird things.

    Edit: After poking around in the code, I understand better what you’re asking now. I’ve just debugged a parameterized test using JUnit 4.10 and it does indeed invoke the constructor once per row per test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a long stored procedure, when I call it i receive the following
This is a weird one. Long story short: wrote a usercontrol using AJAX. Used
I wrote a test WCF service that returns a string array as long as
I wrote this code to test to combine two files: long getFileSize(char *filename) {
Here is a function I wrote to break a long string into lines not
I've met one person who claims he has wrote to over 5000 lines of
I'm reviewing a piece of code I wrote not too long ago, and I
I wrote this report to display how long it takes a user to finish
I wrote a program in python (using standard python libraries) long ago. Now I
Here's the code I wrote for finding the n-th Fibonacci number: unsigned long long

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.