2

I have read some articles regarding how we can implement BDD with cuuumber but i am not able to understand fully.

Lets say i have a service

/v1/picture?viewer=1&viewed=2&flag=1

For these 3 input i am looking for output as "1.jpg"

I am looking for

  1. How can we implement above ? -- i.e output based on input
  2. How can we build data ? -- mysql data basically stubs

Please help with examples and good links. Thanks

  • I think your question is about using BDD for web-services ? please take a look at this answer to a related question: https://stackoverflow.com/a/47799207/143475 – Peter Thomas Dec 18 '17 at 08:50

1 Answers1

1

It's hard to answer your question as there's not a lot of detail about what you're trying to achieve, but I'll give it a go.

You've got 3 different inputs there: - The viewer - Whether it's been viewed or not - A flag.

So those inputs provide different contexts (Givens) for the scenarios.

  • Given a .jpg viewer
  • Given I have already viewed the image twice
  • Given the image has been flagged

How you set up the data for these givens is entirely up to you. You can hard-code it, use mysql data or input real data using an admin console, etc.. It shouldn't matter. The behaviour you're interested in is what happens when you apply the event (When):

  • When I retrieve the v1 picture

Presumably, the input provided in your contexts is relevant, and will provide different outcomes (Thens) depending on that input.

  • Then I should see a .jpg file
  • Then I should see the "Image flagged" banner
  • Then I should see the message "Viewed 2 times"

So I might have scenarios like:

Given a .jpg viewer  
And an image that's been viewed 3 times  
When I retrieve the v1 picture  
Then the service should give me 1.jpg  
And I should see the message "Viewed 3 times"  

Given a .png viewer  
When I retrieve the v1 picture  
Then the service should give me 1.png

etc.

I don't know what your real service is doing, but hopefully this helps you see the pattern. Try to keep different aspects of the behaviour separated in the scenarios (more like the 2nd than the 1st) unless there are combinations you need to exemplify.

Lunivore
  • 17,277
  • 4
  • 47
  • 92