简体   繁体   English

如何从中加载值。 Cucumber-jvm步骤类中的属性文件

[英]How to load a value from . properties file in Cucumber-jvm step class

I have written a cucumber integration tests and it is running ok. 我已经写了一个黄瓜集成测试,它运行正常。

And then i wanted some class variables from the step.java to get their values from .properties values 然后我想从step.java中获取一些类变量,以从.properties值中获取它们的值

public class cucumberStepClass { 
    @Value("${value.from.propertiesfile}")
    private String variable
//rest of integration test
}

Does anyone know how can i inject those values so my test can use them? 有谁知道如何注入这些值,以便我的测试可以使用它们?

Have you enabled integration with spring dependency injection? 您是否启用了与弹簧依赖注入的集成? You need to add the cucumber-spring dependency for that. 你需要添加cucumber-spring依赖性。 See https://docs.cucumber.io/cucumber/state/#spring 请参阅https://docs.cucumber.io/cucumber/state/#spring

To add my two cents to the first answer: remember to annotate the class with @SpringBootTest and @TestPropertySource("classpath:test.properties") . 将我的两分钱加到第一个答案:记得用@SpringBootTest@TestPropertySource("classpath:test.properties")注释该类。 And the properties file should be .properties extension or .xml . 属性文件应该是.properties扩展名或.xml .yml cannot be loaded. .yml无法加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM