testng入门教程16数据驱动(把数据写在xml)
testng入门教程16数据驱动(把数据写在xml)把数据写在xml文件里面,在xml文件右键选择runas---testng执行
下面是case部分:
package test_driver_xml; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; public class ParameterizedTest2{
@Test
@Parameters("myName")
public void parameterTest(String myName) {
System.out.println("Parameterized value is : " + myName);
}
}
下面是xml文件,把数据写在xml文件里面
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="suite1">
<test name="test1">
<parameter name="myName" value="manisha"/>
<classes>
<class name="test_driver_xml.ParameterizedTest2"/>
</classes>
</test>
</suite>
在xml文件右键选择runas---testng执行,下面是执行结果:
[TestNG] Running:
C:\Users\chenjia\workspace\20161220_testng_data_driver\src\test_driver_xml\TestNG.xml Parameterized value is : manisha ===============================================
suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================