TestNG: different test method use different DataProvider with Reflect
来源:互联网 发布:黑马python百度云 编辑:程序博客网 时间:2024/05/19 17:57
<pre name="code" class="java">package qa.testNG;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Iterator;import org.testng.annotations.BeforeMethod;import org.testng.annotations.BeforeTest;import org.testng.annotations.DataProvider;import org.testng.annotations.Parameters;import org.testng.annotations.Test;public class TestOnly {String va;String vb;/*The parameter defined in testNG xml file like: * <parameter name="va" value="this is va value"></parameter>* <parameter name="vb" value="this is vb value"></parameter>*/@Parameters({ "va", "vb" })public TestOnly(String a, String b) {this.va = a;this.vb = b;}@DataProvider(name = "toProvideData")public Iterator<Object[]> toProvideData(Method m) {ArrayList<Object[]> al = new ArrayList<>();switch (m.getName()) {case "testMethodA":al.clear();al.add(new Integer[] { 1, 2 });al.add(new Integer[] { 3, 4 });break;case "testMethodB":al.clear();al.add(new Integer[] { 5, 6 });al.add(new Integer[] { 7, 8 });}return al.iterator();// return new Object[][]{{"a1","a2"},{"b1","b2"}};}@Test(groups = { "dataProviderGroup" }, dataProvider = "toProvideData")public void testMethodA(int a, int b) {System.out.println("Multiples in testMethodA: " + a * b);}@Test(groups = { "dataProviderGroup" }, dataProvider = "toProvideData")public void testMethodB(int a, int b) {System.out.println("Multiples in testMethodB: " + a * b);}@Test(groups = "paraInjectGroup")public void testParameterInject() {System.out.println(va+vb);}@BeforeTest(alwaysRun=true)void beforeTest(){System.out.println("before test");}@BeforeMethod(alwaysRun=true)void beforeMethod(){System.out.println("before method");}}
//testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" ><suite name="Cuke Sample" verbose="1"><span style="white-space:pre"></span><parameter name="va" value="vaaaaaaa"></parameter><span style="white-space:pre"></span><parameter name="vb" value="vbbbbbb"></parameter><span style="white-space:pre"></span><test name="Cukes test1"><span style="white-space:pre"></span><groups><span style="white-space:pre"></span><define name="masterGroup"><span style="white-space:pre"></span><include name="paraInjectGroup"></include><span style="white-space:pre"></span><include name="dataProviderGroup"></include><span style="white-space:pre"></span></define><span style="white-space:pre"></span><run><span style="white-space:pre"></span><include name="masterGroup"></include><span style="white-space:pre"></span></run><span style="white-space:pre"></span></groups><span style="white-space:pre"></span><packages><span style="white-space:pre"></span><package name="qa.testNG"></package><span style="white-space:pre"></span></packages><span style="white-space:pre"></span></test><span style="white-space:pre"></span><span style="white-space:pre"></span><test name="Cukes test2"><span style="white-space:pre"></span><groups><span style="white-space:pre"></span><run><span style="white-space:pre"></span><include name="dataProviderGroup"></include><span style="white-space:pre"></span></run><span style="white-space:pre"></span></groups><span style="white-space:pre"></span><packages><span style="white-space:pre"></span><package name="qa.testNG"></package><span style="white-space:pre"></span></packages><span style="white-space:pre"></span></test></suite>
</pre><pre name="code" class="java">
0 0
- TestNG: different test method use different DataProvider with Reflect
- Use different port to test different website in apache
- How to use SCAN and node listeners with different ports?
- different
- TestNG dataProvider
- TestNG-DataProvider
- Monitor JVM with Different Tools
- Java text with different colors
- a different object with the
- testng 由dataprovider修饰的@test被莫名其妙skip
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- Class file collision: A resource exists with a different case: /test/TestFrame$MyActionListener.clas
- call different method with the same name, parameters and return value, select which one is called using const symbol
- a different object with the same identifier
- CSU 1097 Gifts with different style
- Different Ways to Integrate with PeopleSoft
- QTextEdit with different text colors (Qt / C++)
- FWNX-working diary - enter with different orders-
- chrome浏览器,自定义搜索引擎,让搜索更高效
- iOS-OC 代码风格片段
- netfilter-在内核态操作网络数据包
- 此证书的签发者无效Missing iOS Distribution signing identity问题解决
- react-native for android 学习笔记 (1) DrawerLayoutAndroid
- TestNG: different test method use different DataProvider with Reflect
- Android样式之Selector
- 分布式日志分析系统构建实战(四)——Storm
- 传感器初涉之光照传感器的使用
- poj2184 Cow Exhibition(01背包+变化)
- ':app:transformClassesWithDexForDebug'. > com.android.build.transform.api.TransformException: when i
- 第3章 python实战例子 第一节
- Android样式之layer-list
- 第一篇