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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:19:05+00:00 2026-05-23T08:19:05+00:00

Is it possible to define some test data, for a java program, in a

  • 0

Is it possible to define some test data, for a java program, in a way that enables it to be easily human readable and programmatically parsable into the relevant function calls and data elements.
If it is impossible do achieve in Java I’m open to using Scala for this. The code under test is java code and this will not be ported to Scala.

    interface someInterface {
        class X {
            // the member variables will always either 
            // be enums or intrinsic types 
            private int a;
            public int a() { return this.a; };
            public void a(int a) {this.a = a; };

            private double b;
            public double b() { return this.b; };
            public void b(double b) {this.b = b; };

            private String c;
            public String c() { return this.c; };
            public void c(String c) {this.c = c; };
        }

        enum A {
            A_1,
            A_2
        }
        class Y {
            // assume setters and getters as per X above
            private A a;
            private double b;
            private String c;
            private Z[] z;
        }
        class Z {
            private int a;
            private double b;
            private String c;
        }

        Y function1(X x, String s);
    }

    public void boo() {
        String[] testData = {
            /* how can I specify this array so that 
               coo(...) can be called as below
               would I be better off defining this 
               test code in Scala?
               the classes and interfaces above: 
               someInterface, A, X, Y and Z are in Java 
               and will not be ported to Scala */
        };
        coo(testData);
    }

    public void coo(String[] testData) {
        /* this function will know how to:
               a) parse testData
               b) use reflection to call 
                  someInterface.functionXXX with parameters
                  as specified in testData
               c) construct the return result as specified 
                  in testData and compare against actual 
                  return result */
    }   
}
  • 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-23T08:19:05+00:00Added an answer on May 23, 2026 at 8:19 am

    You can use JUnit 4 for this and run with a Parameterized class.

    Create a test class like this:

    @RunWith(Parameterized.class)
    public class MyTest
    {
          private String s;
          private SomeInterface.X x;
          private SomeInterface someInterface;
    
          @Parameters
          public static Collection<Object[]> prepareData()
          {
                Collection<Object[]> args = new ArrayList<Object[]>();
    
                args.add(new Object[]{"org.some.thing.Impl",  1, 2.6,"Hello", "World"});
                args.add(new Object[]{"org.some.thing.Impl",  2, 2.7,"Goodbye", "World"});
                args.add(new Object[]{"org.some.thing.Impl",  3, 2.8,"Hello", "Universe"});
                args.add(new Object[]{"org.some.thing.Impl2", 4, 2.9,"Goodbye", "Universe"});
    
                return args;        
          }
    
          public MyTest(Object[] args)
          {
                String someInterfaceImplementation = args[0].toString();
    
                someInterface = null;
    
                int a = (Integer) args[1];
                double b = (Double) args[2];
                String c = (String) args[3];
    
                s = (String) args[4];
    
                x = new SomeInterface.X();
                x.a(a);
                x.b(b);
                x.c(c);
          }
    
          @Test
          public void testSomething()
          {
                someInterface.function1(x, s);
          }
     }
    

    Explenation:

    @RunWith(Parameterized.class) tells the JUnit framework to run ask the test class for parameters, and run all the test in the class with those parametrs.
    It expects a Collection of Object[]. Each Object[] is passed via reflection to the constructor of this class.

    prepareData – provides all the scenarios you want to test.

    MyTest(Object[] args) populates the members of this class before running all the tests on a specific parameter set. Important to note that the ‘someInterface` is initialized only once – for each parameter set. If you add more tests for the same parameter set, you might need to re-initialize it.

    testSomething() runs your test. It will run one time per Object[] that prepareData provides. And it is guaranteed to run after the MyTest(Object[] args) has been executed (duh, like you have any alternative here)

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

Sidebar

Related Questions

Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
Is it possible to define a timestamp column in a MySQL table that will
Is it possible to define a class in C# such that class GenericCollection<T> :
I would like to define some aliases in fish. Apparently it should be possible
In my C# program, I have a thread that represents a running test, which
I'm working with a legacy application that makes some use of the well-known/dreaded data
For instance, is the following possible: #define definer(x) #define #x?
In VBP its possible to define user defined actions by creating a custom COM
Is it possible to define a spring-managed EJB3 hibernate listener? I have this definition
Is it possible to define anonymous subroutines in a hash constructor in Perl? I'm

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.