如何用maven运行cucumber-jvm测试

 清清果冻儿 发布于 2023-01-29 18:45

如何使用Maven在以下位置运行我的黄瓜测试.

源文件夹的src/main/java'和'src/main/resources'包括在每个源文件夹中创建的包'com.testing.TestProject.login'中的步骤定义和功能文件.

我在POM文件中包含了插件和依赖项,但是当我运行maven阶段集成测试时,黄瓜测试没有被执行.

我是Maven的新手.请让我知道要在POM文件中包含什么来运行Maven的黄瓜测试.

这是我的POM文件:

   
  4.0.0

  com.testing
  MyMavenProject
  1.0-SNAPSHOT
  jar

  MyMavenProject
  http://maven.apache.org

  
    UTF-8
    1.1.5
    2.39.0
    4.11
  

    

    
        
            org.codehaus.mojo
            exec-maven-plugin
            1.2.1
            
                
                    integration-test
                    
                        java
                    
                
            
            
                
                    info.cukes
                    cucumber-core
                
                cucumber.api.cli.Main
                
                    --format
                    junit:target/cucumber-junit-report/allcukes.xml
                    --format
                    pretty
                    --format
                    html:target/cucumber-html-report
                    --tags
                    @login
                    --glue
                    com/
                    src/
                
            
            
                
                    info.cukes
                    cucumber-core
                    1.1.5
                
            
        
    
  

  
    
      junit
      junit
      ${junit.version}
      test
    
    
        org.seleniumhq.selenium
        selenium-java
        ${selenium.version}
    
    
        info.cukes
        cucumber-picocontainer
        ${cucumber-jvm.version}
        test
    
    
        info.cukes
        cucumber-junit
        ${cucumber-jvm.version}
        test
    
    
    org.testng
    testng
    6.8.7


    log4j
    log4j
    1.2.16


    commons-logging
    commons-logging
    1.1.3



提前致谢.

2 个回答
  • 从Maven运行Cucumber JVM测试的典型方法是通过提供一个RunCukesTest从JUnit触发Cucumber 的类来通过JUnit桥接它们.

    典型的RunCukesTest类可能如下所示:

    package com.testing;
    
    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    import org.junit.runner.RunWith;
    
    @RunWith(Cucumber.class)
    @CucumberOptions(
            features = "src/test/resources/features",
            glue = "com.testing"
    )
    public class RunCukesTest { // NOSONAR SonarLint does not know about @RunWith(Cucumber.class)
    }
    

    细节说明:

    @RunWith(Cucumber.class)告诉JUnit不要使用它的默认运行程序来运行这个测试类,而是使用CucumberJUnit4从JUnit中运行Cucumber的测试运行程序.

    @CucumberOptions告诉Cucumber在哪里找到它的东西.主要的是:

    features告诉Cucumber在哪里找到功能文件.

    glue告诉Cucumber哪些包包含步骤定义.

    2023-01-29 18:48 回答
  • 您的测试类需要以"Test"后缀结束.

    2023-01-29 18:48 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有