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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:03:20+00:00 2026-06-18T01:03:20+00:00

We have a text file where a list of search query and the expected

  • 0

We have a text file where a list of search query and the expected result is given. Such as,

Search Result

a:120         result1
b:220         result2
.....
.....

Now, we need to write a JUnit (heavily used in our daily build) test class, where each of the row will represent one @Test method. So by that, we know, which search case failed (UI).

We already have a solution, where we have one @Test method only, and we have log to check which case passed or failed.

But, we are trying to achieve per case represented as a junit method. Is it really possible, to dynamically create a @Test method to JUnit architecture.

Our, @Test method is same for every search case. That means, we just want to pass a different parameter every time.

I have come up with a JUnit3 solution to my problem. Need help to translate it to Junit4.

public static Test suite()
   {
      TestSuite suite = new TestSuite();
      for ( int i = 1; i <= 5; i++ ) {

         final int j = i;
         suite.addTest(
            new Test1( "testQuery" + i ) {
               protected void runTest()
               {
                  try {
                     testQuery( j );
                  } catch ( MalformedURLException e ) {

                     // TODO Auto-generated catch block
                     e.printStackTrace();
                  } catch ( SolrServerException e ) {

                     // TODO Auto-generated catch block
                     e.printStackTrace();
                  }
               }
            }
            );
      }

      return suite;
   }
  • 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-18T01:03:22+00:00Added an answer on June 18, 2026 at 1:03 am

    In JUnit 4 there is a concept called “Parameterized Test” that is used for exactly this.

    I don’t fully understand your test above, but this should give you a hint:

    @RunWith(Parameterized.class)
    public class ParameterizedTest {
    
        private String query;
        private String expectedResult;
    
        public ParameterizedTest(String query, String expectedResult) {
            this.query = datum;
            this.expectedResult = expectedResult;
        }
    
        @Parameters
        public static Collection<Object[]> generateData() {
            Object[][] data = {
                    { "a:120", "result1" },
                    { "b:220", "result2" },
            };
            return Arrays.asList(data);
        }
    
        @Test
        public void checkQueryResult() {
            System.out.println("Checking that the resutl for query " + query + " is " + expectedResult);
            // ...
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file with a list of strings. I want to search
I have a text file that contains a list of filenames, minus the extension,
I have a list of timestamps in a text file. I want to figure
I have a list Dogs in a text file with the following format: id:fatherid:motherid:born:owner:breed
I have a small Java program that reads list of IPs from text file
Okay, basically, I have a large list of phone numbers in a text file
I have a string buffer of a huge text file. I have to search
I have a list of URLs in a text file I am trying to
I have a text file with some content. I need to search this content
Im still new to python. I have a text file with a list of

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.