我有两个DataProvider
,应该在一个工厂中将数据设置为两种数据类型(长整型和双精度),但是当我运行代码时,测试采用的数据类型就不同,如double和int。
public class FactoryTest {
@Factory(dataProvider ="doubleData")
public Object[] getArithmeticDoubleFunctions(double firstNumber,double secondNumber)
{
System.out.println(String.format("Generate test for user: %s %s", firstNumber, secondNumber));
return new Object[]{new ArithmeticFunctionsTest(firstNumber,secondNumber)};
}
@Factory(dataProvider ="longData")
public Object[] getArithmeticLongFunctions(long firstNumber1,long secondNumber1)
{
System.out.println(String.format("Generate test for user: %s %s", firstNumber1, secondNumber1));
return new Object[]{new ArithmeticFunctionsTest( firstNumber1,secondNumber1)};
}
}
@DataProvider(name="longData")
public Object[][] arithmeticDoubleData() {
return new Object[][]{{10, 12}, {-1,-1},{-1,23},{0,1},{-1,2}};
}
@DataProvider(name="doubleData")
public Object[][] arithmeticLongData() {
return new Object[][]{{10.0, 12.3}, {-1.1,-1},{-1.7,23.2},{0,1.2},{-1.1,2.2}};
}
public ArithmeticFunctionsTest(long firstNumber, long secondNubmer) {
this.firstLongNumber = firstNumber;
this.secondLongNumber = secondNubmer;
}
public ArithmeticFunctionsTest(double firstNumber, double secondNumber) {
this.firstDoubleNumber = firstNumber;
this.secondDoubleNumber = secondNumber;
}
@BeforeClass
public void setUp() {
calculator = new Calculator();
}
@Test
public void testLongSum() {
Assert.assertEquals(calculator.sum(firstLongNumber, secondLongNumber), firstLongNumber + secondLongNumber);
System.out.println(firstLongNumber+" "+secondLongNumber+" Long sum");
}
@Test
public void testDoubleSum() {
Assert.assertEquals(calculator.sum(firstDoubleNumber, secondDoubleNumber), firstDoubleNumber + secondDoubleNumber);
System.out.println(firstDoubleNumber+" "+secondDoubleNumber+"double sum");
}
使用firstNumber
和secondNumber
类型的测试应该只包含具有所需类型的数据提供程序,但是类型混合在一起。
答案 0 :(得分:0)
public class FactoryTest {
@Factory(dataProvider ="doubleData")
public Object[] getArithmeticDoubleFunctions(double firstNumber,double secondNumber)
{
System.out.println(String.format("Generate test for user: %s %s", firstNumber, secondNumber));
return new Object[]{new ArithmeticFunctionsTest(firstNumber,secondNumber)};
}
@Factory(dataProvider ="longData")
public Object[] getArithmeticLongFunctions(long firstNumber1,long secondNumber1)
{
System.out.println(String.format("Generate test for user: %s %s", firstNumber1, secondNumber1));
return new Object[]{new ArithmeticFunctionsTest( firstNumber1,secondNumber1)};
}
@DataProvider(name="longData")
public Object[][] arithmeticDoubleData() {
return new Object[][]{{10, 12}, {-1,-1},{-1,23},{0,1},{-1,2}};
}
@DataProvider(name="doubleData")
public Object[][] arithmeticLongData() {
return new Object[][]{{10.0, 12.3}, {-1.1,-1},{-1.7,23.2},{0,1.2},{-1.1,2.2}};
}