1
我對Selenium webdriver和Java相當陌生,以前我使用過Selenium IDE。我試圖從Excel工作表讀取測試數據。然後將其寫入Eclipse控制檯,該控制檯可以正常工作,並且應該用於執行實際測試,但不起作用。實際測試不會執行,因爲我得到錯誤參數類型不匹配。代碼如下所示:JUnit中的參數類型不匹配
package Test_Excel;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
@RunWith(Parameterized.class)
public class TestWithExcelData {
// Our two parameters
private final int input;
private final int resultExpected;
// Constructor
public TestWithExcelData(int input, int result) {
this.input = input;
this.resultExpected = result;
}
@Parameters
public static Iterable<Object []> data() throws BiffException, IOException
{
String FilePath = "C://Selenium//workspace//testproject//src//testdata//TestData.xls";
FileInputStream fs = new FileInputStream(FilePath);
Object[][] object = new Object[6][2];
Workbook wb = Workbook.getWorkbook(fs);
//locate the excel file in the local machine
Sheet sheet = wb.getSheet("IOResult");
int i=1; //avoid header row
while(!(sheet.getCell(0, i).getContents().equals("end"))) //read data till it reaches the cell whose text is ‘end’
{
object[i-1][0]=sheet.getCell(0, i).getContents();
object[i-1][1]=sheet.getCell(1, i).getContents();
System.out.print(sheet.getCell(0, i).getContents() + "\t");
System.out.print(sheet.getCell(1, i).getContents() + "\t");
System.out.println();
i++;
}
return Arrays.asList(object);
}
@Test
public void testSquareOff(){
Assert.assertEquals(resultExpected, MathUtils.square(input));
}
}
有沒有人能指出我正確的方向?
在此先感謝
你能告訴我們一個堆棧跟蹤? –
順便說一下,您不必將對象數組包裝到JUnit 4.12中的列表中。 data()可能會返回Object [] []。請參閱http://junit.org/javadoc/latest/org/junit/runners/Parameterized.html –