为什么在 TestNg 中使用 {} Parameter annotation syntax

Why {} used in TestNg Parameter annotation syntax

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

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

让我觉得在参数中使用 {} 的原因不同的是 @Test 我们可以传递多个数据,例如 @Test(priority=1, enabled=true) 而我们不使用 {} 这里 in@Test.

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

括号用于arrays/lists。

在 TestNG 的 org.testng.annotations.Parameters 中你可以看到只有一个方法声明 returns 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 中看到的相比,即 priority returns int :

/**
 * The scheduling priority. Lower priorities will be scheduled first.
 */
int priority() default 0;