Eclipse + Maven + Cucumber + Serenity没有测试结果

时间:2016-03-03 18:09:18

标签: eclipse maven testing automation cucumber

好的,所以我已经阅读了我能找到的每一个在线教程。我正在尝试为一个简单的约会应用程序设置BDD测试自动化。在Eclipse中完成所有这些操作的在线文档非常糟糕。我已经在Eclipse中运行了,我在index.html中得到了一个测试文件,但是它说没有测试。 enter image description here

我通过右键单击项目并执行'Run As'Maven build和'Run Configurations'来运行测试我正在进行干净的测试验证。以下是我组织项目的方式。 enter image description here

这是我的SearchByGender.java文件

 package sean;

//package net.serenity_bdd.samples.etsy.features;

import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;

@RunWith( CucumberWithSerenity.class )
@CucumberOptions( features="src/test/resources/features/verify_gender.feature" )

public class SearchByGender {}

这是我的SearchByGenderStepDefinitions.java文件

package sean;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import net.thucydides.core.annotations.Steps;

public class SearchByGenderStepDefinitions
{
    @Steps
    UserProfile profile;

    @Given( "I want a (.*)" )
    public void userWantsToFind() 
    {
        profile.opens_user_profile();
    }

    @When( "I search for profiles containing '(.*)'" )
    public void searchByGender( String gender ) 
    {
        profile.searches_for_profiles_containing( gender );
    }

    @Then( "I should only see profiles related to '(.*)'" )
    public void resultsForGender( String gender ) 
    {
        profile.should_see_profiles_related_to( gender );
    }
}

我的UserProfile.java

package sean;

import net.thucydides.core.annotations.Step;
import net.thucydides.core.steps.ScenarioSteps;
import static org.assertj.core.api.Assertions.assertThat;

public class UserProfile extends ScenarioSteps
{

    private static final long serialVersionUID = 1L;
    private String searched_gender;
    private String status;

    @Step 
    public void opens_user_profile()
    {
        status = "single";
    }

    @Step 
    public void searches_for_profiles_containing( String searched_gender )
    {
        this.searched_gender = searched_gender;
    }

    @Step 
    public void should_see_profiles_related_to( String found_gender )
    {
        assertThat( searched_gender.equals(found_gender) );
    }
}

我的专题文件

Feature: Searching by gender

  In order to find a girlfriend
  As a single male
  I want to be able to profiles containing female

  Scenario: Should list profiles related to a specified gender
    Given I want a girlfriend
    When I search for profiles containing 'female'
    Then I should only see profiles related to 'female'

最后这是我的pom.xml。

<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>net.serenity_bdd.samples.junit</groupId>
    <artifactId>junit-quick-start</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Serenity JUnit Quick Start Project</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <serenity.version>1.0.47</serenity.version>
        <serenity.maven.version>1.0.47</serenity.maven.version>
        <webdriver.driver>firefox</webdriver.driver>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>     
            <artifactId>core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>     
            <artifactId>serenity-junit</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>1.7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <version>1.0.2</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>                  
                <version>2.18</version>
                <configuration>
                    <includes>
                        <include>**/features/**/When*.java</include>                  
                    </includes>
                    <systemProperties>
                        <webdriver.driver>${webdriver.driver}</webdriver.driver> 
                        <surefire.rerunFailingTestsCount>${surefire.rerunFailingTestsCount}</surefire.rerunFailingTestsCount>
                        <surefire.rerunFailingTestsCount>${surefire.rerunFailingTestsCount}</surefire.rerunFailingTestsCount>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>       
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.maven.version}</version>
                <dependencies>
                     <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>core</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>             
                        <goals>
                            <goal>aggregate</goal>                       
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

请帮忙。我必须让这项工作适合我的工作。

1 个答案:

答案 0 :(得分:0)

我通过在Eclipse中使用serenity-cucumber原型创建一个新的Maven项目来解决问题。在我做一个快速入门之前。不知道为什么这解决了问题,但确实如此。可能与插件有关。