gpt4 book ai didi

java - Intellij IDEA 中的 JUnit 错误 "test framework quit unexpectedly"

转载 作者:行者123 更新时间:2023-11-30 06:17:50 26 4
gpt4 key购买 nike

我从不同方面调查了这个问题,但到目前为止没有任何进展。我有一个项目,使用 Cucumber for Java 在 JUnit 上运行 selenium 驱动程序。我使用Maven。这是运行测试的 TestRunner:

package com.task.lab;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "C:\\Users\\admin\\IdeaProjects\\bddtesting\\src\\test\\java\\com\\task\\lab\\features",
glue = "C:\\Users\\admin\\IdeaProjects\\bddtesting\\src\\test\\java\\com\\task\\lab\\steps")
public class TestRunner {
}

这是功能文件:

Feature: Login to Gmail

Scenario Outline: login compose and delete letter
Given: User is on SignIn page
When: User enters <Email> and <Password>
Then: User sends letter to <Receiver> and alert is displayed letter is sent
Examples:
|Email |Password |Receiver
|testaccount@gmail.com |okokokokok |testtest@gmail.com
|testaccount@gmail.com |okokokokok |testtest@gmail.com

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.task.lab.bddtesting</groupId>
<artifactId>bddtesting</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
</dependencies>

最后是我的 Steps.Defs 类:

package com.task.lab.steps;

import com.task.lab.decorator.bo.businessobjects.GmailMessage;
import com.task.lab.decorator.bo.businessobjects.Login;
import com.task.lab.driver.DriverObject;
import com.task.lab.propertyreader.ReadPropertyFile;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDefs {

private Login login = new Login();

@Given("^User is on SignIn page$")
public void openSignInPage(){
LOG.info("Logging in");
DriverObject.getDriver();
DriverObject.getDriver().get(ReadPropertyFile.readGmailURL());
}

@When("^User enters (\\S+) and (\\S+)$")
public void enterCredentials(String email, String password) throws Throwable {
login = new Login();
login.login(email, password);
}

@Then("^User sends letter to (\\S+) and alert is displayed letter is sent$")
public void composeLetter(String receiver){
GmailMessage gmail = new GmailMessage();
gmail.sendMessage(receiver);
}

@After
public void closeBrowser(){
DriverObject.releaseThread();
}
}

当我尝试从窗口运行 TestRunner 时,出现错误未找到测试。正如我之前调查的那样,其原因可能是我运行测试单元,而不是主类。因此,我重新配置了该项目的 Intelij 设置,使其从 Cucumber for Java 运行,并将 Main 类指定为 cucumber.api.cli.Main。但是,这给了我另一个错误测试框架意外退出。我还尝试仅运行功能文件,在这种情况下,测试是绿色的,但实际上,没有通过任何场景或步骤,如控制台中的输出所示:

0 Scenarios
0 Steps
0m0,000s

我也将 Intelij 重新安装到 Ultimate 版本,但结果是一样的。有人可以帮我看看我做错了什么吗?

最佳答案

所以,正如我怀疑的那样,这个问题很小。在我 future 的文件中,我删除了“:”并用垂直线“|”关闭了表格:

Feature: Login to Gmail

Scenario Outline: login compose and delete letter
Given User is on SignIn page
When User enters <Email> and <Password>
Then User sends letter to <Receiver> and alert is displayed letter is sent
Examples:
|Email |Password |Receiver |
|testaccount@gmail.com |okokokokok |testtest@gmail.com|
|testaccount@gmail.com |okokokokok |testtest@gmail.com|

效果非常好。

关于java - Intellij IDEA 中的 JUnit 错误 "test framework quit unexpectedly",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48815085/

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