在 testng 中从 testng.xml 传递参数时出错
Error in passing paramters from testng.xml in testng
我无法访问在 testng.xml.Tried 中定义的参数化值,在测试和方法级别定义参数也是我从这里的其他类似查询中获得的,但错误保持不变
错误是 - “参数 'myName' 是方法 parameterTest 上的 @Test 所必需的,但尚未标记为 @Optional 或已定义
在 C:\Windows\Temp\testng-eclipse-281832880\testng-customsuite.xml"
下面是我的代码片段,后面是testng.xml和错误
Code snippet for one and two params
testng.xml with both param types 1-at test and method level both, 2- at method level
以下对我有效[你只需要确保相同的 class 不会在同一个 <test>
标签中被多次包含。
这是一个示例
package organized.chaos.testng;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class EmployeeTestNG {
@Parameters ({"and", "abc"})
@Test
public void test1(String b, String a) {
System.err.println("****" + b + a);
}
@Test
@Parameters ("myName")
public void parameterTest(String myName) {
System.err.println("Parameterized value is " + myName);
}
}
这是 TestNG 套件 xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="employee-suite">
<test name="Employee-test">
<classes>
<class name="organized.chaos.testng.EmployeeTestNG">
<parameter name="myName" value="TestNG"/>
<parameter name="and" value="KungFu"/>
<parameter name="abc" value="Panda"/>
<methods>
<include name="parameterTest"/>
<include name="test1"/>
</methods>
</class>
</classes>
</test>
</suite>
这是输出
[TestNG] Running:
/Users/krmahadevan/githome/PlayGround/testbed/src/test/resources/employee.xml
Parameterized value is TestNG
****KungFuPanda
===============================================
employee-suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0
我无法访问在 testng.xml.Tried 中定义的参数化值,在测试和方法级别定义参数也是我从这里的其他类似查询中获得的,但错误保持不变 错误是 - “参数 'myName' 是方法 parameterTest 上的 @Test 所必需的,但尚未标记为 @Optional 或已定义 在 C:\Windows\Temp\testng-eclipse-281832880\testng-customsuite.xml"
下面是我的代码片段,后面是testng.xml和错误
Code snippet for one and two params
testng.xml with both param types 1-at test and method level both, 2- at method level
以下对我有效[你只需要确保相同的 class 不会在同一个 <test>
标签中被多次包含。
这是一个示例
package organized.chaos.testng;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class EmployeeTestNG {
@Parameters ({"and", "abc"})
@Test
public void test1(String b, String a) {
System.err.println("****" + b + a);
}
@Test
@Parameters ("myName")
public void parameterTest(String myName) {
System.err.println("Parameterized value is " + myName);
}
}
这是 TestNG 套件 xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="employee-suite">
<test name="Employee-test">
<classes>
<class name="organized.chaos.testng.EmployeeTestNG">
<parameter name="myName" value="TestNG"/>
<parameter name="and" value="KungFu"/>
<parameter name="abc" value="Panda"/>
<methods>
<include name="parameterTest"/>
<include name="test1"/>
</methods>
</class>
</classes>
</test>
</suite>
这是输出
[TestNG] Running:
/Users/krmahadevan/githome/PlayGround/testbed/src/test/resources/employee.xml
Parameterized value is TestNG
****KungFuPanda
===============================================
employee-suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0