Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Cucumber 6和Maven集成集成测试_Maven_Cucumber_Integration Testing_Integration - Fatal编程技术网

如何使用Cucumber 6和Maven集成集成测试

如何使用Cucumber 6和Maven集成集成测试,maven,cucumber,integration-testing,integration,Maven,Cucumber,Integration Testing,Integration,我真的需要帮助 目标:使用cucumber-Java8 6.7.0版和Maven 3.6.3运行my cucumber集成测试 实际场景:当我使用以下命令运行maven时:$mvn clean verify-Pintegration tests我收到了这个结果 xxxxx @ xxx <Project Name> % mvn clean verify -Pintegration-tests [INFO] Scanning for projects... [INFO] [INFO]

我真的需要帮助

目标:使用cucumber-Java8 6.7.0版和Maven 3.6.3运行my cucumber集成测试

实际场景:当我使用以下命令运行maven时:
$mvn clean verify-Pintegration tests
我收到了这个结果


xxxxx @ xxx <Project Name> % mvn clean verify -Pintegration-tests
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------< <Project Name> >----------
[INFO] Building <Project Name> 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ <Project Name> ---
[INFO] Deleting /Users/<home>/Documents/repos/xxx/<Project Name>/target
[INFO] 
[INFO] --- build-helper-maven-plugin:3.1.0:add-test-source (add-source) @ <Project Name> ---


***[INFO] Test Source directory: /Users/<home>/Documents/repos/xxxx/<Project Name>/src/testintegration added.***


[INFO] 
[INFO] --- build-helper-maven-plugin:3.1.0:add-test-resource (add-resource) @ <Project Name ---
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ <Project Name> ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 13 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ <Project Name> ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 223 source files to /Users/<home>/Documents/repos/xxx/<Project Name>
...
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ <Project Name> ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 15 resources
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ n<Project Name> ---
[INFO] Changes detected - recompiling the module!

...

[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ <Project Name> ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ <Project Name> ---
[INFO] Building jar: /Users/<home>/Documents/repos/xxxx/<Project Name> -server/target/<Project Name>.jar
[INFO] 
[INFO] --- maven-failsafe-plugin:2.22.2:integration-test (default) @ <Project Name> ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-failsafe-plugin:2.22.2:verify (default) @ <Project Name> ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.484 s
[INFO] Finished at: 2020-10-17T13:07:50+01:00
[INFO] ------------------------------------------------------------------------
 




代码场景实际

Maven文件-剪断 特征文件的一部分 Runner类-(当我通过Intellij触发该类时,我的测试运行正确 我用这个页面试着做我的测试,但说实话,我不知道我是否做错了什么,或者文章遗漏了什么。

拜托,有人能检查一下Pom.xml文件吗?我想我遗漏了什么

如果有人能在这里帮助我,非常感谢


干杯,

试着让你的问题变得更小。尝试一个JUnit测试。以
mvn测试运行它。
。然后添加一个简单的JUnit集成测试,并使用
mvn验证运行它。
。然后添加Cucumber,但省去你添加的所有额外内容。您好@M.p.Korstanje,非常感谢,但我已经尝试过了。当我运行简单的单元测试时,就可以了被发现并成功运行。我的问题是,当我尝试基于功能文件运行我的定义类时。非常感谢!!!我很乐意提供更多建议。:-)那么,您最好提出一个新问题,用这个简单得多的配置确切地说明什么不起作用。你现在有太多的活动部件。删除实际上不需要显示问题的所有内容@M.P.Korstanje,我部分解决了这个问题。我发现我必须使用Cucumber的图书馆。io.junit平台引擎${cucuber.io.version},但是使用junit的集成测试停止工作。当我找到解决方案时,我会在这里发布。非常感谢!:)
@RunWith(Cucumber.class)
@CucumberOptions(
    features = {"src/testintegration/java/features"},
    glue = {"steps"},
    plugin = {"pretty", "html:target/cucumber"},
    publish = true)
public class RunCucumberIT {

 <!-- Integration tests -->

  <profiles>
    <profile>
      <id>integration-tests</id>

      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>

      <properties>
        <cucumber.plugin>json:target/report.json</cucumber.plugin>
        <cucumber.filter.tags>@wip</cucumber.filter.tags>
      </properties>

      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.7</version>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>add-source</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>add-test-source</goal>
                </goals>
                <configuration>
                  <sources>
                    <source>src/testintegration/</source>
                  </sources>
                </configuration>
              </execution>
              <execution>
                <id>add-resource</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>add-test-resource</goal>
                </goals>
                <configuration>
                  <resources>
                    <resource>
                      <directory>src/testintegration/resources/features</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <!-- block unit tests execution -->
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin.version}</version>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <systemPropertyVariables>
                <cucumber.plugin>${cucumber.plugin}</cucumber.plugin>
                <cucumber.filter.tags>${cucumber.filter.tags}</cucumber.filter.tags>
              </systemPropertyVariables>
            </configuration>
          </plugin>
        </plugins>
      </build>


      <dependencies>
        <!-- Cucumber -->
        <dependency>
          <groupId>io.cucumber</groupId>
          <artifactId>cucumber-java8</artifactId>
          <version>${cucumber.version}</version>
          <scope>test</scope>
        </dependency>

        <dependency>
          <groupId>io.cucumber</groupId>
          <artifactId>cucumber-junit</artifactId>
          <version>${cucumber.version}</version>
          <scope>test</scope>
        </dependency>

        <dependency>
          <groupId>io.cucumber</groupId>
          <artifactId>cucumber-java</artifactId>
          <version>6.2.2</version>
          <scope>test</scope>
        </dependency>

      </dependencies>
    </profile>
  </profiles>
</project>

package steps;

import static org.junit.jupiter.api.Assertions.assertTrue;

import io.cucumber.java8.En;


public class Authorization implements En {

  public Authorization() {

    Given("the system knows about the following attributes",
        (io.cucumber.datatable.DataTable dataTable) -> {
          System.out.println("AUTHORIZATION GIVEN TEST");
          assertTrue(true);
        });

    When("the client request POST \\/login", () -> {
      System.out.println("AUTHORIZATION When TEST");
      assertTrue(true);
    });

    Then("the response should be JSON", (io.cucumber.datatable.DataTable dataTable) -> {
      System.out.println("AUTHORIZATION Then TEST");
      assertTrue(true);
    });

  }
}

Feature: Authorization

  @wip
  Scenario: Login into account

...
package runner;

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

@RunWith(Cucumber.class)
@CucumberOptions(
    features = {"src/testintegration/java/features"},
    glue = {"steps"},
    plugin = {"pretty", "html:target/cucumber"},
    publish = true)
public class RunCucumberIT {
  
}