【问题标题】:Junit Data Driven test using only selected Datapoints仅使用选定数据点的 Junit 数据驱动测试
【发布时间】:2012-12-17 07:13:46
【问题描述】:

我有 3 个字符串数组数据点和 2 个整数数组数据点。

@DataPoint public static Integer[] xxx ={100,200};
@DataPoint public static Integer[] x ={-14,15};
@DataPoint public static String[] xx = new String[]{"de" ,"Y"};
@DataPoint public static String[] cityCode = new String[]{"de" ,"abc"};
 @DataPoint public static String[] city = new String[]{"de" ,"dfg"};


@Theory public void xxx(String[] result ,Integer[] checkdt ) 

运行此测试用例时,它需要 3 个字符串数组的数据点,但我只想使用字符串数组的 2 个数据点 我怎样才能只使用 2 个数据点?

【问题讨论】:

    标签: java junit data-driven


    【解决方案1】:

    您可以使用Assume 过滤数据点。在测试开始时,添加如下内容:

    @Theory public void xxx(String[] result ,Integer[] checkdt )  {
        Assume.assumeTrue("Y".equals(result[1]);
        // rest of test
    }
    

    【讨论】:

      【解决方案2】:

      据我了解,specific DataPointspecicfic Theory 之间没有选择。

      每个@Theory 都将针对@DataPoint 的输入参数运行。

      您是否要过滤 DataPoint 数据您可以断言您想要的输入数据并运行休息。

      【讨论】:

      • 如何过滤 DataPoint 数据
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多