简体   繁体   English

DataProvider不适用于外部整数

[英]DataProvider doesn't work with external integer

My @DataProvider looks like this: 我的@DataProvider看起来像这样:

    @DataProvider(name = "data")
    public Object[][] data() throws Exception {
    List myList= DBHelper.getList("SELECT x FROM property"); //Get DB data to list
    Object[] myArray = myList.toArray();//Convert to array
    int len = myArray .length; //Get max array index
    int randomIndex = General.createRandNumber(len); //create a random index
    return new Object[][]{
            {myArray [randomIndex]},
            {myArray [randomIndex]},
    };
}

When I am running the @Test I get Test ignored - unless I replace randomIndex with a real number, for example: {myArray [0]}, 当我运行@Test时,我会忽略测试 - 除非我用实数替换randomIndex,例如:{myArray [0]},

I am unable to figure out why that happens and would like to hear the explanation for that. 我无法弄清楚为什么会发生这种情况,并希望听到解释。

Thanks. 谢谢。

Figure that out... 想出来......

The problem was that I was using len as the length of the randomize number which result with non-existing DB index. 问题是我使用len作为随机数的长度,这是由于不存在的DB索引导致的。 That is why the test failed. 这就是测试失败的原因。 Sometime you get confused from the simple things... (-: 有时你会对简单的事情感到困惑......( - :

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM