下面是@DataProvider有name和没有name时

有name的时候可以引用name 即:@DataProvider(name="testData")---------->@Test(dataProvider="testData")

package data_driver;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; public class TestDataDriven {
@DataProvider(name="testData")
public Object[][] dataProvider(){
return new Object[][]{{1,2},{2,3},{3,4}};
} @Test(dataProvider="testData")
public void testDataDriven(int a,int b){
System.out.println("this is :"+(a+b));
}
}

右键----->RunAs----->TestNG test   运行结果如下:

[TestNG] Running:
C:\Users\chenjia\AppData\Local\Temp\testng-eclipse--2116911479\testng-customsuite.xml this is :3
this is :5
this is :7
PASSED: testDataDriven(1, 2)
PASSED: testDataDriven(2, 3)
PASSED: testDataDriven(3, 4) ===============================================
Default test
Tests run: 3, Failures: 0, Skips: 0
=============================================== ===============================================
Default suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================

没有name的时候可以引用方法名即:

package data_driver;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestDataDriven{
@DataProvider
public Object[][] dataprovider(){
return new Object[][]{{1,2},{2,3},{3,4},{4,5},{5,6}}; } @Test(dataProvider="dataprovider")
public void testDataDriven(int a, int b){
System.out.println("this is :"+ (a + b));
}
}

右键----->RunAs----->TestNG test   运行结果如下:

[TestNG] Running:
C:\Users\chenjia\AppData\Local\Temp\testng-eclipse-1345547329\testng-customsuite.xml this is :3
this is :5
this is :7
this is :9
this is :11
PASSED: testDataDriven(1, 2)
PASSED: testDataDriven(2, 3)
PASSED: testDataDriven(3, 4)
PASSED: testDataDriven(4, 5)
PASSED: testDataDriven(5, 6) ===============================================
Default test
Tests run: 5, Failures: 0, Skips: 0
=============================================== ===============================================
Default suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================

testng入门教程13同文件数据驱动的更多相关文章

  1. testng入门教程16数据驱动(把数据写在xml)

    testng入门教程16数据驱动(把数据写在xml) testng入门教程16数据驱动(把数据写在xml)把数据写在xml文件里面,在xml文件右键选择runas---testng执行 下面是case ...

  2. testng入门教程12 TestNG执行多线程测试

    testng入门教程 TestNG执行多线程测试 testng入门教程 TestNG执行多线程测试 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者 ...

  3. TestNG 入门教程【转】

    TestNG 入门教程[转] 国庆7天假期,大部分朋友都出去旅游了,微信圈里全是晒旅游的照片, 东南亚游,欧洲游呀,真是羡慕呀. 悲惨的我只去了上海野生动物园, 在家休息,利用这段假期,把之前学过的东 ...

  4. TestNG 入门教程

    原文出处:http://www.cnblogs.com/TankXiao/p/3888070.html 阅读目录 TestNG介绍 在Eclipse中在线安装TestNG 在Eclipse中离线安装T ...

  5. TestNG入门教程

    阅读目录 TestNG介绍 在Eclipse中在线安装TestNG 在Eclipse中离线安装Testng TestNG最简单的测试 TestNG的基本注解 TestNG中如何执行测试 使用testt ...

  6. ABP入门教程13 - 更新菜单

    点这里进入ABP入门教程目录 菜单更新 在展示层(即JD.CRS.Web.Mvc)的Startup下打开CRSNavigationProvider.cs //用以存放菜单相关信息 修改如下 using ...

  7. testng入门教程14数据驱动(不同文件)

    数据与test脚本不在同一文件时,下面是数据: package data_driver_two_parts; import org.testng.annotations.DataProvider; p ...

  8. testng入门教程15数据驱动

    testng在类 里面的数据驱动 package driver_test; import org.testng.annotations.DataProvider; import org.testng. ...

  9. testng入门教程10 TestNG参数化测试

    在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大的不同数量的测试.参数测试,允许开发人员运行同样的测试,一遍又一遍使用不同的值. TestNG让你 ...

随机推荐

  1. vuex - 辅助函数学习

    官网文档: https://vuex.vuejs.org/zh-cn/api.html  最底部 mapState 此函数返回一个对象,生成计算属性 - 当一个组件需要获取多个状态时候,将这些状态都声 ...

  2. JUnit —— TestSuite 的使用

    首先说一下,suite ,中文是 一套,一组 的意思. 那么,TestSuite,顾名思义,就是用来运行一组测试的. 如何使用呢 ? 假设有个这样的测试类 StudentDAOTest ,代码如下: ...

  3. Android6.0中PowerManagerService分析

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=30510400&id=5569393 概述 一直以来,电源管理是 ...

  4. word2010没有“标题2、标题3”样式的解决办法

    word2010没有“标题2.标题3”样式的解决办法 很多人用word的时候都喜欢用“标题1”“标题2”等样式来定义他们的文档标题,被这样定义的标题会出现在导航窗格中,使浏览起来非常方便.但是最近我发 ...

  5. sencha touch 在安卓中横屏、竖屏切换 应用崩溃问题

    答案来至于 Sencha Touch 交流 @周旭 这是由于横竖屏转换导致activity重跑onCreate方法导致的,有两种解决方案:1.横竖屏转换的时候不要重新跑onCreate方法,这个可以在 ...

  6. sencha touch NavigationView

    NavigationView 是官方根据Container控件扩展而来的,由一个导航栏和一个card组成,具备导航和返回时自动销毁当前界面的功能,非常适合新手使用. 其中导航栏的代码如下: Ext.d ...

  7. vue--提取公共方法

    在做一个项目的时候,一些组件内公用的方法可以单独提取出来做复用: 参考:https://www.jb51.net/article/115662.htm 简单示例: 代码: const config = ...

  8. HOJ 2148&POJ 2680(DP递推,加大数运算)

    Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...

  9. PAT甲1038 Recover the smallest number

    1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...

  10. hdu 2444 The Accomodation of Students 【二分图匹配】

    There are a group of students. Some of them may know each other, while others don't. For example, A ...