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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:30:09+00:00 2026-05-22T11:30:09+00:00

I am using JUnit 4 parametrized test annotations to perform equality tests on data

  • 0

I am using JUnit 4 parametrized test annotations to perform equality tests on data coming from a unknown number of files.

For some weird reason, the test always checks the same file, as if the same Array was always used from the Collection used to pass the parameters.

I’m sure I’m missing something elementary here, but I can’t see what. Could someone provide me with a helpful tip ?

Here is my code :

 @RunWith(value = Parameterized.class)
 public class XMLUnitTest extends XMLTestCase {

static final File ORACLE_DIR = new File("some/directory/path");
static final String PATH_TO_LOG = "some/file/path";

private String oracleXml;
private String testXml;
private String testName;

public XMLUnitTest(String o, String t, String n) {
    this.oracleXml = o;
    this.testXml = t;
    this.testName = n;
}

// (snip) file-handling methods

@Parameters
static public Collection<Object[]> data() {

    String logfile = null;

    File[] xmlFilesArray;
    ArrayList<String> parsedXMLs = new ArrayList<String>();
    ArrayList<String> xmlNames = new ArrayList<String>();

    String[] xmlArgs = new String[3];
    Collection<Object[]> data = new ArrayList<Object[]>();

    try {logfile = readFileAsString(PATH_TO_LOG);} 
    catch (IOException e) {// (snip) error handling}

    String[] parsedLogs = logfile.split("someRegex", 0);

    for (int i = 0; i < parsedLogs.length; i++) {
        parsedLogs[i] = "<xml>"+parsedLogs[i]+"</xml>";
    }

    xmlFilesArray = ORACLE_DIR.listFiles();
    Arrays.sort(xmlFilesArray, nameCompare);
    for (int i = 0; i < xmlFilesArray.length; i++) {
        if (!xmlFilesArray[i].isDirectory()) {
            try {
                parsedXMLs.add(convertXMLFileToString(xmlFilesArray[i].getAbsolutePath()));
                xmlNames.add(xmlFilesArray[i].getName());
            } 
            catch (Exception e) {// (snip) error handling}
        } 
    }

    for (int i = 0; i < parsedLogs.length; i++) {
        xmlArgs[0] = parsedXMLs.get(i);
        xmlArgs[1] = parsedLogs[i];
        xmlArgs[2] = xmlNames.get(i);
        System.out.println(xmlArgs[2]); //debug
        data.add(xmlArgs);
    }

    return data;
}

@SuppressWarnings("unchecked")
@Test
public void equality() throws Exception {

    System.out.println("Working on test: "+testName);
    // (snip) some testing
}
}

It’s partially obfuscated but there should be everything needed to find my error…

The System.out.prints are used for debug : the one in the static parameter-generator show the names of the correct files, meaning that the object “data” is correct. The one in the test itself always prints the same thing, meaning that the test is always run with the same array of parameters (But it runs 7 times, the number of arrays I have in my collection !) I don’t get it. Is there something I have missed about the type of the parameters to pass to JUnit ?

  • 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-22T11:30:10+00:00Added an answer on May 22, 2026 at 11:30 am

    This
    String[] xmlArgs = new String[3];
    should be in the for-loop.
    Your are always updating the same instance of the xmlArgs-Array and inserting it..

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

Sidebar

Related Questions

I'm currently re-using JUnit 4 tests from another project against my code. I obtain
I am using data-driven test suites running JUnit 3 based on Rainsberger's JUnit Recipes
I'm developing in Java and using JUnit to test some of my methods. Some
I'm trying to run some tests in Ant presently using JUnit, and all of
I am using JUnit to do some automated tests on my application, the tests
I'm trying to write some GUI and integration tests using JUnit and FEST. Here
At work we are currently still using JUnit 3 to run our tests. We
We have a lot of integration tests written using JUnit 3 , though we're
I am comparing text files in junit using: public static void assertReaders(BufferedReader expected, BufferedReader
I'm trying to run my junit tests using ant. The tests are kicked off

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.