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

  • Home
  • SEARCH
  • 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 4267464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:54:11+00:00 2026-05-21T06:54:11+00:00

I have an interface that defines the behaviour of an object that does some

  • 0

I have an interface that defines the behaviour of an object that does some graph search called say GraphSearcher. I currently have a bunch of different implementations with more variations on the way and so I have defined the test classes as being abstract with concrete test methods and an abstract method that instantiates an implementation of graph searching object.

This is all fine except that I have a bunch of different classes (about 10 at the moment) that each run whole lot of tests based on some real world data. This means that for each concreate implementation I end up writing a whole lot test classes just containing the instantiation method.

This all seemed kind of messy to me and I was wondering if anyone knew of a better solution. I think ideally I would like to be able to pass in a GraphSearcher factory object into some sort of test suite and have all the various test classes run. This would mean that I would only have to write a tiny bit of code to have a new GraphSearcher implementation run against all the tests. I’m just not sure how to go about this using junit 4. I’m sure there must be some fairly standard way to do this but I haven’t been able to find anything yet. Any pointers anyone has would be greatly appreciated

  • 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-21T06:54:11+00:00Added an answer on May 21, 2026 at 6:54 am

    If I understand your problem well, you just have some testing code and would like to run it multiple times, each time with a different implementation of GraphSearcher, right? If so, I would probably go with a Paremeterized JUnit runner. It could look like this:

    @RunWith(Parameterized.class)
    public class GraphSearcherTest
    {
        private GraphSearcher testedSearcher;
    
        public GraphSearcherTest(GraphSearcher searcher)
        {
            this.testedSearcher = searcher;
        }
    
        @Parameters
        public static Collection<Object[]> getParameters()
        {
            return Arrays.asList(new Object[][] {
                    { new GraphSearcherImpl1() },
                    { new GraphSearcherImpl2() }
            });
        }
    
        @Test
        public void testGraphSearcher()
        {
            // execute the test
            testedSearcher.search();
    
            // make some assertions
        }
    }
    

    The key parts are:

    • the @RunWith(Parameterized.class) annotation
    • the constructor which takes the tested implementation of GraphSearcher
    • the @Parameters-annotated method (of arbitrary name) which returns Collection. This method will be called for every item of the collection and the object from the collection will be added to the test’s constructor.
    • the size of the Object[] in the collection must match the number of arguments of the constructor

    So in this case the test will be called twice. First test will get the GraphSearcherImpl1 instance and the second the GraphSearcherImpl2 instance in its constructor.

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

Sidebar

Related Questions

I have a interface that defines some methods with attributes. These attributes need to
I have an interface that defines some methods I would like certain classes to
I have an Interface called IStep that can do some computation (See Execution in
Lets say you have interface definition. That interface can be Operation . Then you
Say I have the following interface that I want to share between my server
I have a simple object that holds some [public] data. I want to keep
I have an interface that I have defined in C++ which now needs to
I have a very thin interface that's going to define one method. Should I
I have an NSWindow that I defined in interface builder. I want to make
I have an interface that needs to react to long key presses. That means

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.