为什么{}在TestNg中使用参数注释语法

问题描述 投票:0回答:1

我想知道为什么@parameter({"a,"b"})testNG的语法有这个额外的{}括号。

我对这个主题的研究可能是因为我们必须在这里指定多个数据。

是什么让我认为在参数中使用{}的原因是不同的是在@Test我们可以传递像@Test(priority=1, enabled=true)这样的多个数据,我们在这里不使用{} in@Test

请帮助我理解这一点,无论我的想法是正确的方向还是背后的更多。

testng
1个回答
0
投票

括号用于数组/列表。

在TestNG的org.testng.annotations.Parameters中,您可以看到只有一个返回String []的方法声明:

/**
 * The list of variables used to fill the parameters of this method.
 * These variables must be defined in your testng.xml file.
 * For example
 * <p>
 * <code>
 * &#064;Parameters({ "xmlPath" })<br>
 * &#064;Test<br>
 * public void verifyXmlFile(String path) { ... }<br>
 * </code>
 * <p>and in <tt>testng.xml</tt>:<p>
 * <code>
 * &lt;parameter name="xmlPath" value="account.xml" /&gt;<br>
 * </code>
 */
public String[] value() default {};

相比之下,您可以在testNG的org.testng.annotations.Test中看到,即优先级返回int:

/**
 * The scheduling priority. Lower priorities will be scheduled first.
 */
int priority() default 0;
© www.soinside.com 2019 - 2024. All rights reserved.