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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:26:05+00:00 2026-05-25T21:26:05+00:00

@DataPoints public static final Integer[] input1={1,2}; @Theory @Test public void test1(int input1){ } @DataPoints

  • 0
@DataPoints public static final Integer[] input1={1,2};
@Theory
@Test
public void test1(int input1){

}

@DataPoints public static final Integer[] input2={3,4};
@Theory
@Test
public void test2(int input2 ){

}

I want that test1 runs with data set input1 – {1,2} and test2 runs with input2 – {3,4}. But currently each test runs with both the data sets {1,2,3,4}. How to bind specific @DataPoints to specific @Theorys

  • 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-25T21:26:05+00:00Added an answer on May 25, 2026 at 9:26 pm

    DataPoints apply to the class. If you have a @Theory method which takes an int, and you have a DataPoint which is an array of ints, then it will be called with the int.

    @RunWith(Theories.class)
    public class TheoryTest {
        @DataPoint public static int input1 = 45;
        @DataPoint public static int input2 = 46;
        @DataPoints public static String[] inputs = new String[] { "foobar", "barbar" };
    
        @Theory public void testString1(String input) {
            System.out.println("testString1 input=" + input);
        }
    
        @Theory public void testString2(String input) {
            System.out.println("testString2 input=" + input);
        }
    
        @Theory public void test1(int input) {
            System.out.println("test1 input=" + input);
        }
    
        @Theory public void test2(int input) {
            System.out.println("test2 input=" + input);
        }
    }
    

    This calls test1 with 45 & 46, and test2 with 45 & 46. It calls testString1 with “foobar” and “barbar” and testString2 with “foobar” and “barbar”.

    If you really want to use different data sets for different theories, you can wrap the data in a private class:

    @RunWith(Theories.class)
    public class TheoryTest {
        public static class I1 { int i; public I1(int i) { this.i = i;} }
        public static class I2 { int i; public I2(int i) { this.i = i;} }
    
        @DataPoint public static I1 input1 = new I1(45);
        @DataPoint public static I2 input2 = new I2(46);
    
        @Theory
        public void test1(I1 input) {
            System.out.println("test1 input=" + input.i);
        }
    
        @Theory
        public void test2(I2 input) {
            System.out.println("test2 input=" + input.i);
        }
    }
    

    This calls test1 with 45 and test2 with 46. This works, but in my opinion, it obscures the code, and it may be a better solution to just split the Test class into two classes.

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

Sidebar

Related Questions

private void Form1_Load(object sender, EventArgs e) { GetDataTable(@C:\Documents and Settings\agordon\Desktop\ACTIVITYEX.csv); } public System.Data.DataTable GetDataTable(string
I have a chart control in XAML, and datapoints that are bind to the
Is this bug in Parallel.For? public class DataPoint { public int Game { get;
I have datapoints of different classes which I want to visualize. Here is the
I have an example class containing two data points: public enum Sort { First,
I have a set of X,Y data points (about 10k) that are easy to
I've started using the new(ish) JUnit Theories feature for parameterizing tests. If your Theory
I want to put some error handling in my code. I can not figure
i have these double values: public partial class Window1 : Window { public Window1()
I had en idea, which shortly explained was that i would like to load

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.