testNG+ATS
1.testNG插件
1.离线安装
TestNG Eclipse插件下载地址http://testng.org/doc/download.html
下载下来以后,放在eclipse的plugins文件夹下,然后启动eclipse。
然后去Windows -> show view -> other,java文件夹下,有TestNG,双击图标,在eclipse界面下面便会出现TestNg的窗体。
2.在线安装
Help->Install New Software,然后在弹出的窗口中的Work with后面的输入框中输入http://beust.com/eclipse
然后点击Add按钮,选中TestNG后一路点击Next下去安装即可,直到Finished之后,重启Eclipse完成安装。
2.ATS插件
ats插件是支付宝定制插件,主要实现参数化和快捷新建接口脚本等
PS.CSV参数化
目前我们的用例通过CSV脚本进行维护的,因此我们测试基类里编写了一个DataProvider。具体定义如下:
//@DataProvider(name = "CsvDataProvider")
//public Iterator<?> getDataProvider(Method method) {}
@Override
@DataProvider(name = "CsvDataProvider")
public Iterator<?> getDataProvider(Method method) throws IOException {
String file = "";
if (null != method.getAnnotation(TestData.class)) {
String env = StringUtil.contains(PropertyConfig.DB_MODE, "dev")?"dev":"test";
file = method.getAnnotation(TestData.class).path()
+ method.getAnnotation(TestData.class).fileName()+ env + ".csv";
logger.info("++++++++++++++++++++++++++++" + file);
return getDataProvider(method.getDeclaringClass(), method, file);
} else
logger.info("============================" + file);
return getDataProvider(method.getDeclaringClass(), method);
}
测试类继承测试基类,测试类示例如下
@TestLab(id = "Testtest001", desc = "正常业务场景测试")
public class Testtest extends TestBase {
private static final Logger logger = LoggerFactory.getLogger(GetConfigNormalTest.class);
@XAutoWire(value = XAutoWire.BY_NAME, bundle = "com.tset")
protected Test tset;
@TCList(caseid = { "Testtest001001" }, casedesc = { "正常业务场景测试" })
@Test(dataProvider = "CsvDataProvider", description = "正常业务场景测试")
public void tset(final String caseId, final String description,
final String tset001, final String tset002, final String defValue) {
TestVo testVo = new TestVo();
testVo.setTset001(tset001);
testVo.setTset002(tset002);
TestenumEnum testenum = TestenumEnum.SUPPORTED_LINES;
Test.tset(tset001,tset002,configKey,defValue)