首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果函数有@Test注释,如何使用函数参数?

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

Stack Overflow用户
提问于 2015-07-02 06:23:32
回答 1查看 68关注 0票数 3

如果函数有@test注释,是否有任何方法在函数中使用参数。我的功能如下:

代码语言:javascript
复制
@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();       
    }

然而,当我试图运行以上代码时,它会给我带来错误:

方法Home_page_Flextronics需要两个参数,但@Test注释中提供了0。

如果我删除参数并使用硬编码的值,它的工作良好,这是我的框架的要求。我已经研究过其他解决方案,大多建议使用@Parameter注释或数据提供程序。但我不想使用它,因为我想从excel表中获取测试数据。如果还有别的办法可以处理,请告诉我。谢谢你提前帮忙。

EN

回答 1

Stack Overflow用户

发布于 2015-07-02 06:42:30

你可以看看Junit理论(导言)

代码语言:javascript
复制
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);
  }
}

这样,您就可以将参数传递给测试。在带有DataPoints注解的方法中,您需要获取所有超能力数据并返回它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31176928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档