如何在不同的类中使用@DataProvider

时间:2017-05-01 07:35:15

标签: testing automated-tests testng dataprovider testng-dataprovider

如何使用另一个类中的import sys import math from PyQt5 import QtGui,QtCore from PyQt5.QtCore import pyqtSlot,pyqtSignal from PyQt5.QtGui import QGuiApplication app = QGuiApplication(sys.argv) Range = 2000.0 Brg = 330.0 Crs = 120.0 Elevation = 50.0 V = 40.0 TGt_x = Range * math.cos(Elevation) * math.sin(Brg) TGt_y = Range * math.cos(Elevation) * math.cos(Brg) TGt_z = Range * math.sin(Elevation) Vx = V * math.sin(Crs) Vy = V * math.cos(Crs) Vz = 0.0 def compute(): TGt_z = TGt_z + Vz TGt_x = TGt_x + Vx TGt_y = TGt_y + Vy print("TGTx=============================",TGt_x) print("TGTy=============================", TGt_y) print("TGTz=============================",TGt_z) Range = math.sqrt(pow(TGt_x, 2) + pow(TGt_y, 2) + pow(TGt_z, 2)) print("Range=============================",Range,"\n") timer = QtCore.QTimer() timer.timeout.connect(compute) timer.setInterval(1000) timer.start() sys.exit(app.exec_())*

我创建了一个不同的包,并且我在每个测试用例旁边定义了数据提供程序。请分享我如何在另一个班级中使用它。

2 个答案:

答案 0 :(得分:12)

您可以使用dataProviderClass的{​​{1}}属性:

@Test

查看the documentation了解详情。

答案 1 :(得分:0)

如果您有唯一的dataProvider方法名称(createData),并且如果您选择不在DataProvider注释之后给出名称,则

@DataProvider    
public Object[][] createData(){

}

然后你可以使用如下方法名称,

@Test(dataProvider = "createData", dataProviderClass = StaticProvider.class)