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

孤人 提交于 2019-12-10 14:59:11

问题


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

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?


回答1:


Have you enabled integration with spring dependency injection? You need to add the cucumber-spring dependency for that. See https://docs.cucumber.io/cucumber/state/#spring




回答2:


To add my two cents to the first answer: remember to annotate the class with @SpringBootTest and @TestPropertySource("classpath:test.properties"). And the properties file should be .properties extension or .xml. .yml cannot be loaded.



来源:https://stackoverflow.com/questions/36936970/how-to-load-a-value-from-properties-file-in-cucumber-jvm-step-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!