简体   繁体   中英

Lettuce BDD - Values in scenario defined in config file

I'm pretty new to BDD and Lettuce and I cam across an issue which I'm not sure how best to handle.

I want to create a Lettuce test suite which I can then run against different environments, where some parameters in the scenario would be different for each environment.

So following the Lettuce documentation I have this example scenario:

Scenario: Create correct config
          Given I have IP "127.0.0.0:8000" 
          And I specify username "myuser" and password "mypassword"
          When I connect to the server
          Then I get return code 200

In this case I would have to change the IP, user and password for each environment. But this is not practical and I want to be able to have some config file which I can create for each environment and it would contain the value for these parameters.

I found out about terrain.py and saw that you can set variables in this file which you can access from your steps.py using world .

So it would be possible to re-word the scenario like this:

Scenario: Create correct config
          Given I have a correct IP
          And I specify correct credentials
          When I connect to the sever
          Then I get return code 200

Now in the step definitions example for " I have a correct IP " you can use world.correctIP which will be defined in terrain.py .

This would work in the way I need it to, but I'm not convinced this is the correct way to do it and if terrain.py was intended to be used like this...or is there a different way to handle this situation?

I would say that hiding the implementation details is a good approach. That is, I have a correct IP is a better way to go than keeping this detail in a property file.

BDD is all about communication. If it is enough to know that you use the correct ip, then there is no need to know which ip when you read the example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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