使用testng测试注释运行时跳过了方法。如何提供参数?我访问了testng文档,但无法';我不明白,请引导

使用testng测试注释运行时跳过了方法。如何提供参数?我访问了testng文档,但无法';我不明白,请引导,testng,Testng,代码: package tests; import org.testng.annotations.Test; @Test public class SearchText { public void createzoo(String[] args) { String[] elems = {"lion", "tiger", "duck"}; System.out.println(elems[0]); System.out.pr

代码

package tests;

import org.testng.annotations.Test;

@Test
public class SearchText {


    public void createzoo(String[] args) {  

        String[] elems = {"lion", "tiger", "duck"};  
        System.out.println(elems[0]);
        System.out.println(elems[1]);
        System.out.println(elems[2]);
    }
}
结果:

跳过:createzoo org.testng.TestNGException:方法createzoo 需要1个参数,但@Test注释中提供了0


以下是相关文档:

您需要在
createzoo
方法中提供参数
String[]args
的值。以下是几种方法:

  • 在方法上使用注释,并在testng.xml文件中提供值
  • (塞德里克在答复中也提到了这一点)
  • 在参数上添加注释并提供默认值

阅读TestNG文档-它有很多关于如何实现这一点的示例。

示例createzoo方法实际上没有使用传入的参数。 由于未使用它们,只需将消息签名更改为:

public void createzoo()
大多数JUnit/TestNG测试不接受任何参数。 您可能会将其与具有公共静态void main(String[]args)的典型程序混淆

测试本身没有
main()
,框架将为您运行测试


如果您确实需要其他人提到的参数,并且该方法将对这些参数进行处理,则只能使用这些参数

你到底不明白什么?文档确实提供了示例..您是否尝试过。那些都出来了?嗨,塞德里克,我有一个关于testng的无关问题。请帮帮我。谢谢