如果函数有@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();
}然而,当我试图运行以上代码时,它会给我带来错误:
方法Home_page_Flextronics需要两个参数,但@Test注释中提供了0。
如果我删除参数并使用硬编码的值,它的工作良好,这是我的框架的要求。我已经研究过其他解决方案,大多建议使用@Parameter注释或数据提供程序。但我不想使用它,因为我想从excel表中获取测试数据。如果还有别的办法可以处理,请告诉我。谢谢你提前帮忙。
发布于 2015-07-02 06:42:30
你可以看看Junit理论(导言)
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注解的方法中,您需要获取所有超能力数据并返回它。
https://stackoverflow.com/questions/31176928
复制相似问题