【问题标题】:running testrunner with cucumber用黄瓜运行 testrunner
【发布时间】:2023-03-05 02:11:01
【问题描述】:

我在用黄瓜运行 testrunner 时遇到问题。我需要有人帮我检查@CucumberOptions。谢谢

package stepDefinition;

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

@RunWith (Cucumber.class)
@CucumberOptions (features = "Feature"
                   ,glue={"stepDefinition"})

public class testRunner {

}

【问题讨论】:

  • 添加问题,什么是项目结构?对于功能,您需要添加保存功能文件的目录路径,例如 src\test....\feature\。对于胶水添加包类路径 cucumber.test.steps

标签: junit cucumber cucumber-junit


【解决方案1】:

@RunWith(Cucumber.class) 用于 JUnit 集成。 如果你想在 TestNG 中使用 Cucumber,你必须使用 AbstractTestNGCucumberTests 扩展你的类。

你应该看看https://github.com/lionhearth/cucumber-testng,这是一个完美的样本。

【讨论】:

  • 谢谢juherr,我希望以junit而不是testng的身份运行。感谢您提供的补充信息。
【解决方案2】:

这是我的测试。我在 src 中有两个步骤定义/功能文件作为包。另外,我下载了黄瓜插件,但我看不到我的功能中显示的颜色。如何参考特征和步骤定义@cucumberoptions。

package stepDefinition;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;


public class aptitudeTest {

    @Given ("^I have successfully ([^\"]*)$")
    public void I_have_(String str)
    {
        if (str.equals("registered"))
        {
            System.out.println("registered Automation");
        }
        if (str.equals("unregistered"))
        {
            System.out.println("unregistered");
        }
    }

    @When ("^I enter my valid ([^\"]*)$")
    public void I_enter_(String str)
    {
        if (str.equals("credentials"))
        {
            System.out.println("credentials Automation");
        }
        if (str.equals("details"))
        {
            System.out.println("details");
        }
    }

        @Then ("^I should see the welcome([^\"]*)him $")
        public void I_should_(String str)
        {
            if  (str.equals("message"))
            {
                System.out.println("message Automation");
            }
            if (str.equals("information"))
            {
                System.out.println("infomation");
            }
        }
    }

这是我的特色

功能:登录帐户

@tester 场景:我成功登录后应该会看到一条消息

鉴于我已成功注册 当我输入我的有效凭据时 然后我应该会看到欢迎信息

鉴于我已成功取消注册 当我输入我的有效详细信息时 然后我应该会看到欢迎信息

【讨论】:

  • 我已经解决了上述问题。我发现我缺少 cucumber-core 依赖。此外,cucumber-core、cucumber-java、cucumber-junit 都必须具有相同的版本。在另一个帖子的某个地方找到了这个
猜你喜欢
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-17
相关资源
最近更新 更多