gpt4 book ai didi

java.lang.Exception : Test class should have exactly one public zero-argument constructor:

转载 作者:行者123 更新时间:2023-12-01 07:52:49 24 4
gpt4 key购买 nike

我有一个类:函数库,我在构造函数中实例化 webdriver 实例,如下所示

public class FunctionLibrary {
public WebDriver driver;

public FunctionLibrary(WebDriver driver)
{
driver = new FirefoxDriver();
this.driver=driver;
}

public WebDriver getDriver(){
return this.driver;
}
}

我正在访问扩展父类(super class)的子类中的 webdriver 实例:函数库

public class Outlook extends FunctionLibrary{
public Outlook(WebDriver driver) {
super(driver);
}

@Before
public void testSetUp()
{
getDriver().navigate().to("https://google.com");
}

@After
public void closeTest()
{
getDriver().close();
}

@Test
public void openOutlookAndCountTheNumberOfMails()
{
System.out.println("executed @Test Annotation");
}
}

当我执行上面的junit代码时我收到错误为

java.lang.Exception: Test class should have exactly one public zero-argument constructor

任何人都可以告诉我哪里出错了

最佳答案

不需要将参数传递到FunctionLibrary的构造函数中,因为您只需覆盖它的值即可:

public class FunctionLibrary {
public WebDriver driver;

public FunctionLibrary()
{
this.driver=new FirefoxDriver();
}

// etc.
}

进行此更改意味着您不需要从测试类传递参数:只需删除其构造函数即可。

关于java.lang.Exception : Test class should have exactly one public zero-argument constructor:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34397700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com