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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:04:03+00:00 2026-05-16T06:04:03+00:00

I wrote a mockup example to illustrate this without exposing anything confidential. It’s a

  • 0

I wrote a mockup example to illustrate this without exposing anything confidential. It’s a “dummy” example which does nothing, but the problem occurs in the test initialiser.

@RunWith(Parameterized.class)
public class ExampleParamTest
{
 int ordinal;
 List<String> strings;

 public ExampleParamTest(int ordinal, String... strings)
 {
  this.ordinal = ordinal;
  if (strings.length == 0)
  {
   this.strings = null;
  }
  else
  {
   this.strings = Arrays.asList(strings);
  }
 }

 @Parameters
 public static Collection<Object[]> data() {
  return Arrays.asList(new Object[][] {
    {0, "hello", "goodbye"},
    {1, "farewell"}
  });
 }

 @Test
 public void doTest() {
  Assert.assertTrue(true);
 }
}

Basically I have a test constructor which accepts multiple arguments for a local list variable and I want to populate this through an array initialiser. The test method will handle the local list variable correctly – I have removed this logic to simplify the test.

When I write this, my IDE has no complaints about syntax and the test class builds without any compile errors. However when I run it, I get:

doTest[0]:
java.lang.IllegalArgumentException: wrong number of arguments
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
doTest[1]:
java.lang.IllegalArgumentException: argument type mismatch
  at java.lang.reflect.Constructor.newInstance(Unknown Source)

What exactly has gone wrong here, and how do I correctly use this pattern?

  • 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-16T06:04:03+00:00Added an answer on May 16, 2026 at 6:04 am

    Can’t test it right now but I guess, if you invoke a method or a constructor with variable arguments, you have to invoke it with an array instead of a variable list of values.

    If I’m right, then this should work:

    @Parameters
     public static Collection<Object[]> data() {
      return Arrays.asList(new Object[][] {
        {0, new String[]{"hello", "goodbye"}},
        {1, new String[]{"farewell"}}
      });
     }
    

    Some explanation

    On source code level, we can write

    test = ExampleParamTest(0, "one", "two");
    

    The compiler will convert this to an array of Strings. JUnit uses the reflection and invocation API, and from this perspective, the constructors signature is

    public ExampleParamTest(int i, String[] strings);
    

    So to invoke the constructor – and that’s what JUnit is doing internally – you have to pass an integer and a String array.

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

Sidebar

Related Questions

I wrote this code which is working but it made me start thinking how
I wrote a tweak for cydia , but it does not seem to be
I wrote a php code that display error in red color. But somehow, this
I wrote a simple XML file and a DTD file including an entity, but
I wrote a makefile which behaves oddly. You can find it here: http://pastebit.com/pastie/8215 Basically
I wrote this code to do the IEEE 754 floating point arithmetic on a
I wrote this: protected void btnup_Click(object sender, EventArgs e) { if (ASPxUploadControl1.HasFile) { try
I wrote a callback (I believe it's called) like this: hugeFadeIn(); It's a simple
I wrote this code: float b = 3.6; and I get this: Error:Unresolved compilation
To make my explanation shorter, I've made this mockup of what I'm trying to

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.