当前位置: 首页 > 知识库问答 >
问题:

无法读取应用程序。cucumber试验中的yml

陆高峰
2023-03-14

我有一个cucumber测试:

@RunWith(CucumberWithSerenity.class)
@UsePersistantStepLibraries
@CucumberOptions(
        features = "src/integrationTest/resources/features/",
        glue = {"com/myorg/proj/integrationtest/stepdefinitions"},
        plugin = {"pretty", "summary"}
)
public class integrationTestRunner extends ParentClassWithAllMethods {


}

这是一个测试,它不是在测试文件夹中定义的,而是一个seprate文件夹(作为源集,其他人创建了这个结构)。

源集(测试所在)的gradle配置如下:

sourceSets {
    integrationTest {
        html" target="_blank">java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integrationTest/java')
        }
        resources.srcDir file('src/integrationTest/resources')
    }
}

// Dependencies for integrationTest
dependencies {
    integrationTestCompileOnly 'org.projectlombok:lombok:1.18.12'
    integrationTestAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
    integrationTestCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.4.2'
    integrationTestImplementation 'net.serenity-bdd:serenity-core:2.2.13'
    integrationTestImplementation 'net.serenity-bdd:serenity-cucumber5:2.2.5'
    integrationTestImplementation 'net.serenity-bdd:serenity-rest-assured:2.2.13'
    integrationTestImplementation 'org.assertj:assertj-core:3.8.0'
    integrationTestImplementation 'org.slf4j:slf4j-simple:1.7.7'

}

task integrationTest(type: Test) {
    doFirst {
        systemProperty 'param1', 
        System.getProperty('param1')
        param1 = System.getProperty('param1')
        if (param1 == null)
          throw new GradleException("Parameter not passed ./gradlew -DParam<VALUE> ")
    }
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }
    finalizedBy aggregate
}

看看gradle文件,有三件事,

  1. 有一个源集定义为集成测试
  2. 编译CLassPath, runTimeClassPath, srcDir已被定义为相同的
  3. 甚至resources.srcDir也在设置中(我有应用ymls)

我已经创建了一个应用程序。yml,应用集成测试。yml在resources文件夹中,但仍然无法使用@Value读取任何比例。

前任:

public class ParentClassWithAllMethods {

  @Value("${custom.parameter}")
  private String customParameter;

  public ResponseOptions<Response> getMethod() {

        String debugVal = customParameter;
  }
.....
}

当运行测试时,我希望得到在我的yml文件中定义的值,但它为null。

YML文件看起来像这样,

自定义:参数:https://something.com

为什么我无法读取应用程序配置?它总是空的!!

共有1个答案

缑泓
2023-03-14

您的测试类不是从Spring开始的,这就是为什么您得到null。看看这里https://www.baeldung.com/cucumber-spring-integration,它展示了如何在JUnit测试中连接Spring和Cucumber。

然后,测试类会对Spring和Cucumber进行这样的注释:

@CucumberContextConfiguration
@SpringBootTest
public class SpringIntegrationTest {
   // executeGet implementation
}
 类似资料:
  • 我无法读取项目中作为bean从另一个项目注入的类中的application.properties值。我的项目正在使用另一个项目,该项目的类需要从application.properties中读取配置。Mine是一个maven项目和一个Spring Boot应用程序,在src/main/resources文件夹中有application.properties,这些属性值在其中定义。我错过了什么,它无

  • 我有一些非常类似于下面的代码(我不得不做一些困惑)。我正在获取一个应用程序启动失败的错误。未显示的代码是datasource bean和spring boot application类。当我在debug中放置断点并运行所有bean时,所有bean似乎都被创建了,除了Job和Step bean,这两个bean似乎被完全跳过了。我不确定如何进一步诊断。似乎是一些Spring的魔法问题。任何想法都非常感

  • My AndroidManifest.xml 文件 我的Gradle 我尝试清理/重建 gradle 项目、重新启动 Android Studio、使缓存失效和 rebbot ADB 集成(工具 - 有什么想法吗? 附言:在此之前,我更改了应用程序包的名称 P、 Android Studio无法调试其他项目。

  • 我已经在谷歌驱动器的应用程序文件夹中创建了一个文件。 编写文件的代码 读取文件的代码 driveContentsResult的状态为false。我看过谷歌的演示,但找不到解决方案。谁能帮我找出我做错了什么,或者我可以尝试的其他方法是什么。

  • 我正在使用Selenium进行iOS移动应用测试。我在使用相应的 我正在使用一个shell脚本来帮助我检查ios\u webkit\u debug\u代理是否可用。如果不存在,它将在2秒内启动ios\u webkit\u debug\u代理。 我的测试很顺利。但在appium中仍然面临一些问题,appium被停止肯定会给出一个 我试着用各种方法来解决这个问题。 重新启动Appium并再次运行。 但

  • 我在Unity中使用Firebase包。当我在Unity编辑器中运行游戏时,它工作得非常好,然而,当我为Android构建游戏时,我得到了这个错误: 无法从应用程序的资源中读取firebase选项,请确保google-services.json包含在您的构建中,或者直接指定选项 谢了!