[在运行测试运行器时将输出设为0方案

问题描述 投票:3回答:3

我正在尝试进行一些测试,作为浸出黄瓜的一部分。但是我得到的结果是0个场景。在这里,我要添加我编写的代码:

Login.feature with-

Feature: Application Login   S
Scenario : Home page default login

    Given User is on Net banking landing page
    When user login into the application with  username and password
    Then Home page is populated
    And Cards are displayed

步骤定义

package stepDefinitions;

import cucumber.api.PendingException;

import cucumber.api.java.en.Given;

import cucumber.api.java.en.When;

import cucumber.api.java.en.Then;

import cucumber.api.java.en.And;

import cucumber.api.junit.Cucumber;

import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class StepDefinition {

    @Given("^User is on Net banking landing page$")
    public void user_is_on_net_banking_landing_page() throws Throwable {
        System.out.println("User on landing page");
    }

    @When("^user login into the application with  username and password$")
    public void user_login_into_the_application_with_username_and_password() throws Throwable {
        System.out.println("Login successfully");
    }

    @Then("^Home page is populated$")
    public void home_page_is_populated() throws Throwable {
        System.out.println("User on Home page");
    }

    @And("^Cards are displayed$")
    public void cards_are_displayed() throws Throwable {
        System.out.println("Displaying cards");
    }

}

Test Runner-

package com.edstem.CucumberOptions;

import cucumber.api.CucumberOptions;

import cucumber.api.junit.Cucumber;

import org.junit.runner.RunWith;

@RunWith(Cucumber.class)

@CucumberOptions(
            features = "src/test/java/features",
            glue = {"stepDefinitions"})

public class TestRunner {
}

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>org.example</groupId>
    <artifactId>cucumber-learning</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.0.11</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>datatable</artifactId>
            <version>1.1.12</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>4.2.3</version>
        </dependency>


    </dependencies>

</project>

输出:0场景0步0m0.000s

处理完成,退出代码为0features =“ src / test / java / features”,

您能给我一个解决方案,因为我找不到解决方法。

maven cucumber cucumber-java
3个回答
2
投票

Scenario:之间的空格是问题

替换此

Scenario : Home page default login

使用

Scenario: Home page default login

1
投票

假设您的特征文件正确放置在src/test/java/features中,问题是您的胶水没有正确设置为步骤定义,或者类路径缺少配置文件路径。

检查两者,如果仍然无法运行,请发布您的运行配置和项目结构。


1
投票

1)您不需要使用@RunWith注释步骤定义类。只要亚军就可以了

2)功能应放置在src / test / resources / features而不是src / test / java中

3)您正在使用非常旧的黄瓜。尝试切换到最新版本

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>

© www.soinside.com 2019 - 2024. All rights reserved.