1. 建立 Java 測試類測試
2. 添加測試方法 TestngParameterTest(String name, String age)ui
3. 爲測試方法添加註釋 @Parameters({"name", "age"})spa
建立 Java 類:code
1 package roger.testng; 2 3 import org.testng.annotations.Parameters; 4 import org.testng.annotations.Test; 5 6 public class TestngParameterTest { 7 @Test 8 @Parameters({"name", "age"}) 9 public void parameterTest(String name, String age) { 10 System.out.println("name: " + name + ", age: " + age); 11 } 12 }
建立 testng.xmlxml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <suite name="testngTest"> 3 <test name="test1"> 4 <parameter name="name" value="roger" /> 5 <parameter name="age" value="27" /> 6 <classes> 7 <class name="roger.testng.TestngParameterTest" /> 8 </classes> 9 </test> 10 </suite>
運行 testng.xml 文件blog
[TestNG] Running:
E:\Selenium_New\JavaForSeleniumLearning\testng.xml
name: roger, age: 27
===============================================
testngTest
Total tests run: 1, Failures: 0, Skips: 0
===============================================