我目前正在使用 Cucumber、JUnit 和 Selenium 开发 Java 测试框架。我已经参与过类似的项目,但我在这个项目上遇到了问题。
我正在尝试创建一个单例的 Context 类。我想使用 cucumber-picocontainer 在每个步骤定义类中访问此类。我在 pom.xml 中添加了依赖项,但每次尝试执行测试时,都会出现异常:“NewLoginSteps 没有空构造函数。如果需要 DI,请将 cucumber-picocontainer 放在类路径上” 。我尝试手动导入罐子,但没有帮助。
这是我的配置示例:
TestContext.java:
public class TestContext {
private static Map<String, String> siteLocations = new HashMap<String, String>();
private static boolean initialized = false;
private static boolean firstInitDone = false;
private static WebDriver driver;
private static boolean testsToRun = false;
private static AutomatedTestMode modeAsEnum;
@Before
public void setUp(Scenario scenario) {
initialize();
Log.startTestCase(scenario.getName());
afterAll();
}
....
}
步骤定义类:
public class NewLoginSteps extends NewSuperSteps {
public NewLoginSteps(TestContext context){
super(context);
}
@When("^I log in nova as \"([^\"]*)\" user with \"([^\"]*)\" \"([^\"]*)\"$")
public void newLogin(String instance, String username, String password){
Assert.assertEquals(true, false);
}
@Then("^The user is connected$")
public void The_user_is_connected(){
throw new PendingException();
}
}
我的超级七年级课程:
public class NewSuperSteps {
protected TestContext context;
public NewSuperSteps(TestContext context){
this.context=context;
}
}
你知道我做错了什么吗?我已经使用 picocontainer 来做同样的事情并且它正在工作。
我遇到了类似的问题。
问题出在信息 cukes 的版本上。您的 pom.xml 中需要所有 cucumber-* 的版本相同。
这为我解决了这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)