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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:58:09+00:00 2026-06-12T07:58:09+00:00

I used to write JUnit tests as methods, such as: public class TextualEntailerTest {

  • 0

I used to write JUnit tests as methods, such as:

public class TextualEntailerTest {
  @Test test1() {...}
  @Test test2() {...}
  @Test test3() {...}
}

Since most of the test cases has a similar structure, I decided to be “data-driven”, and put the contents of the tests in XML files. So, I created a method “testFromFile(file)” and changed my test to:

public class TextualEntailerTest {
  @Test test1() { testFromFile("test1.xml"); }
  @Test test2() { testFromFile("test2.xml"); }
  @Test test3() { testFromFile("test3.xml"); }
}

As I add more and more tests, I become tired of adding a line for each new test file I add. Of course I can put all files in a single test:

public class TextualEntailerTest {
  @Test testAll() { 
     foreach (String file: filesInFolder) 
       testFromFile(file); 
  }
}

However, I prefer that each file will be a separate test, because this way JUnit gives nice statistics about the number of files passed and failed.

So, my question is: how to tell JUnit to run separate tests, where each test is of the form “testFromFile(file)”, for all files in a given folder?

  • 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-12T07:58:10+00:00Added an answer on June 12, 2026 at 7:58 am
    @RunWith(value = Parameterized.class)
    public class JunitTest {
    
         private String filename;
    
         public JunitTest(String filename) {
            this.filename= filename;
         }
    
         @Parameters
         public static Collection<Object[]> data() {
           Object[][] data = new Object[][] { { "file1.xml" }, { "file2.xml" } };
           return Arrays.asList(data);
         }
    
         @Test
         public void Test() {
           System.out.println("Test name:" + filename);
         }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used to write code like this: class P {}; class Q: public P
I used Response.Write to write dynamic javascript into a page to test some values
I have Autowired a field in Test class @Autowired private AbcDAO abcDAO; and used
I am attempting to write some JUnit tests for my android application. The application
I have a Java class for use with JUnit 4.x. Within each @Test method
Several methods I've used to write to files return a BOOL signifying their success,
I'm new to concurrency in Java. I've used Junit to test some of my
I have a generics class that I used to write data to IsolatedStorage. I
When I used to write test tools in Windows, I use MFC for creating
Are the same methods used to write CSS only for iPhone in landscape mode?

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.