简体   繁体   English

没有胶水文件的简单黄瓜测试班通过

[英]Simple Cucumber Test Class Passes with no Glue File

This has been puzzling me for half a day now. 这已经困扰了我半天了。 I can't seem to find the issue. 我似乎找不到问题。 Basically I have my Test runner, feature file, and the steps file in my workspace. 基本上,我的工作区中有测试运行器,功能文件和步骤文件。 The java files are in the same package (ie no package). Java文件位于同一软件包(即无软件包)中。

Below is my TestRunner.java 下面是我的TestRunner.java

import org.junit.Test;
import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "test/resources/features", tags = { "~@Ignore" })
public class TestRunner {

    @Test
    public void feature() {
    }
}

My feature file, helloWorld.feature 我的功能文件helloWorld.feature

Feature: Simple Test Feature

Scenario: Run Scenario ONE
GIVEN step one
WHEN step two
THEN step three

and my steps file CucumberJava.java , 和我的步骤文件CucumberJava.java

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

public class CucumberJava {

    @Given("^step one$")
    public void step_one() {

        System.out.println("step one");
    }

    @When("step two")
    public void step_two() {
        System.out.println("step two");
    }

    @Then("^step three$")
    public void step_three() {
        System.out.println("step three");
    }
}

When I execute TestRunner.java as JUnit, everything passes, but I get the following in the console: 当我将TestRunner.java作为JUnit执行时,一切都通过了,但是在控制台中得到了以下内容:

0 Scenarios
0 Steps
0m0.000s

WHY? 为什么? In fact, when I remove CucumberJava.java from the project, I get the exact same output. 实际上,当我从项目中删除CucumberJava.java时,我得到的输出完全相同。 What am I missing? 我想念什么? I also tried setting the glue option in TestRunner.java code too; 我也尝试在TestRunner.java代码中设置glue选项。 still the same result. 结果还是一样。

Your help is highly appreciated. 非常感谢您的帮助。

The feature file words like Given etc are in uppercase in your feature file. 要素(Given)等要素文件单词在要素文件中为大写。 They need to be like Given ie sentence case. 他们需要像给定的那样,即句子大小写。

Feature: Simple Test Feature

Scenario: Run Scenario ONE
Given step one
When step two
Then step three

Also you might need to append a 'src' to the feature path in the runner. 同样,您可能需要在流道中的特征路径后附加一个“ src”。 Like this features = "src/test/resources/features" , if you are using Maven. 如果您使用的是Maven,则此features = "src/test/resources/features" Also no need to have a @Test annotation and method inside the runner. 同样也不需要在运行程序内部使用@Test annotation and method

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM