Java 如果函数有@Test注释,如何使用函数参数?

Java 如果函数有@Test注释,如何使用函数参数?,java,testng,Java,Testng,如果函数有@test注释,有没有办法在函数中使用参数。我有如下功能: @Test(@Test(priority=1, alwaysRun =true)) public void Home_page_Flextronics(String sUserName, String sPassword) throws FileNotFoundException { CommonFunctions.LaunchApplication(); Co

如果函数有
@test
注释,有没有办法在函数中使用参数。我有如下功能:

@Test(@Test(priority=1, alwaysRun =true))
public void Home_page_Flextronics(String sUserName, String sPassword) throws FileNotFoundException 
    {
        CommonFunctions.LaunchApplication();            
        CommonFunctions.Login(sUserName, sPassword);    
        CommonFunctions.ClickOnModule("Customers"); 
        CommonFunctions.ClickOnHome();
        CommonFunctions.Logout();       
    }
但是,当我尝试运行上述代码时,它会给我错误:

方法主页\u伟创力需要2个参数,但提供了0 在@Test注释中


如果我删除参数并使用硬编码的值,它工作正常,这是我的框架的要求。我也经历过其他的解决方案,主要建议使用
@Parameter
注释或数据提供者。但我不想使用它,因为我想从excel工作表中获取测试数据。请让我知道,如果有任何其他方式来处理这个问题。提前感谢您的帮助。

您可以看看Junit理论


通过这种方式,您可以将参数传递给测试。在用数据点注释的方法中,您需要获取所有Excel数据并返回它。

等待。您希望您的测试数据来自Excel电子表格吗?@Makoto很高兴他没有说Access;-)是的,我想要excel表格中的数据。@TomJonckheere:至少可以谈论Access数据库,即使它是在背后尖锐的耳语。我以前从未见过从Excel电子表格中获取测试数据的请求;可能的原因是您必须测试您的测试是否正确地拉入Excel数据。伙计们,如果您不知道,也可以。我在问题中已经提到,我不想使用@parameters或dataprovider并使用xml推送数据。我知道其他的方法。我问这个是因为这是我的要求。
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertTrue;

@RunWith(Theories.class)
public class AdditionWithTheoriesTest {

  @DataPoints
  public static int[] positiveIntegers() {
       return new int[]{
                        1, 10, 1234567};
  }

  @Theory
  public void a_plus_b_is_greater_than_a_and_greater_than_b(Integer a, Integer b) {
      assertTrue(a + b > a);
      assertTrue(a + b > b);
  }
}