Writing Cucumber scenarios for reactive code









up vote
1
down vote

favorite












I am very new to BDD, and having a bit of trouble outlining the scenarios for some code that I wrote. The code basically queries a Couchbase bucket for abandoned orders, and then calls a cancel order API to cancel those orders. For each call to the cancel order API, it calls another service to generate access token.



The entire code has been written in RxJava. In case of errors, I have fallback observables in place (for example, should anything go awry while querying Couchbase, it fallbacks to an empty observable). I have similar fallbacks in other places in the code as well.



I want to write Cucumber scenarios for my code. But I can't figure out how to go about it. For example, should I assume that the service has a valid access token and an orderId to cancel (querying CB returns a bunch of orderIds that need to be passed on to the cancel order API along with an access token)?



Ideally, I should be testing the following:



  1. Querying Couchbase fails. In this case, I should get an empty observable.


  2. Call to the access token API fails. In this case as well, I should get an empty observable.


  3. Call to the cancel order API fails. In this case as well, I should get an empty observable.


  4. Call to cancel order API returns some response code other than 200. Then assert on the response codes.


  5. The happy case.


Now suppose I want to test the first case, that is, querying CB fails. What will be the background in this case? How should I simulate a query failure?










share|improve this question





















  • I think you are planning your tests on the wrong level. Cucumber should be used for testing the domain level of your application in such a manner that a business analyst can understand your tests. At best, the tests should be technology agnostic, i.e. they should not need to know about the underlying tech stack, which in this case is RxJava. The cases you describe are more or less error cases and IMO unit tests are best suited for these scenarios. Use Cucumber to test "one level higher" i.e. the components that use these Observables returning data. Use mocks to setup the appropriate start data
    – kaskelotti
    Nov 14 at 19:04














up vote
1
down vote

favorite












I am very new to BDD, and having a bit of trouble outlining the scenarios for some code that I wrote. The code basically queries a Couchbase bucket for abandoned orders, and then calls a cancel order API to cancel those orders. For each call to the cancel order API, it calls another service to generate access token.



The entire code has been written in RxJava. In case of errors, I have fallback observables in place (for example, should anything go awry while querying Couchbase, it fallbacks to an empty observable). I have similar fallbacks in other places in the code as well.



I want to write Cucumber scenarios for my code. But I can't figure out how to go about it. For example, should I assume that the service has a valid access token and an orderId to cancel (querying CB returns a bunch of orderIds that need to be passed on to the cancel order API along with an access token)?



Ideally, I should be testing the following:



  1. Querying Couchbase fails. In this case, I should get an empty observable.


  2. Call to the access token API fails. In this case as well, I should get an empty observable.


  3. Call to the cancel order API fails. In this case as well, I should get an empty observable.


  4. Call to cancel order API returns some response code other than 200. Then assert on the response codes.


  5. The happy case.


Now suppose I want to test the first case, that is, querying CB fails. What will be the background in this case? How should I simulate a query failure?










share|improve this question





















  • I think you are planning your tests on the wrong level. Cucumber should be used for testing the domain level of your application in such a manner that a business analyst can understand your tests. At best, the tests should be technology agnostic, i.e. they should not need to know about the underlying tech stack, which in this case is RxJava. The cases you describe are more or less error cases and IMO unit tests are best suited for these scenarios. Use Cucumber to test "one level higher" i.e. the components that use these Observables returning data. Use mocks to setup the appropriate start data
    – kaskelotti
    Nov 14 at 19:04












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am very new to BDD, and having a bit of trouble outlining the scenarios for some code that I wrote. The code basically queries a Couchbase bucket for abandoned orders, and then calls a cancel order API to cancel those orders. For each call to the cancel order API, it calls another service to generate access token.



The entire code has been written in RxJava. In case of errors, I have fallback observables in place (for example, should anything go awry while querying Couchbase, it fallbacks to an empty observable). I have similar fallbacks in other places in the code as well.



I want to write Cucumber scenarios for my code. But I can't figure out how to go about it. For example, should I assume that the service has a valid access token and an orderId to cancel (querying CB returns a bunch of orderIds that need to be passed on to the cancel order API along with an access token)?



Ideally, I should be testing the following:



  1. Querying Couchbase fails. In this case, I should get an empty observable.


  2. Call to the access token API fails. In this case as well, I should get an empty observable.


  3. Call to the cancel order API fails. In this case as well, I should get an empty observable.


  4. Call to cancel order API returns some response code other than 200. Then assert on the response codes.


  5. The happy case.


Now suppose I want to test the first case, that is, querying CB fails. What will be the background in this case? How should I simulate a query failure?










share|improve this question













I am very new to BDD, and having a bit of trouble outlining the scenarios for some code that I wrote. The code basically queries a Couchbase bucket for abandoned orders, and then calls a cancel order API to cancel those orders. For each call to the cancel order API, it calls another service to generate access token.



The entire code has been written in RxJava. In case of errors, I have fallback observables in place (for example, should anything go awry while querying Couchbase, it fallbacks to an empty observable). I have similar fallbacks in other places in the code as well.



I want to write Cucumber scenarios for my code. But I can't figure out how to go about it. For example, should I assume that the service has a valid access token and an orderId to cancel (querying CB returns a bunch of orderIds that need to be passed on to the cancel order API along with an access token)?



Ideally, I should be testing the following:



  1. Querying Couchbase fails. In this case, I should get an empty observable.


  2. Call to the access token API fails. In this case as well, I should get an empty observable.


  3. Call to the cancel order API fails. In this case as well, I should get an empty observable.


  4. Call to cancel order API returns some response code other than 200. Then assert on the response codes.


  5. The happy case.


Now suppose I want to test the first case, that is, querying CB fails. What will be the background in this case? How should I simulate a query failure?







unit-testing testing cucumber rx-java project-reactor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 10:23









Prashant Pandey

18112




18112











  • I think you are planning your tests on the wrong level. Cucumber should be used for testing the domain level of your application in such a manner that a business analyst can understand your tests. At best, the tests should be technology agnostic, i.e. they should not need to know about the underlying tech stack, which in this case is RxJava. The cases you describe are more or less error cases and IMO unit tests are best suited for these scenarios. Use Cucumber to test "one level higher" i.e. the components that use these Observables returning data. Use mocks to setup the appropriate start data
    – kaskelotti
    Nov 14 at 19:04
















  • I think you are planning your tests on the wrong level. Cucumber should be used for testing the domain level of your application in such a manner that a business analyst can understand your tests. At best, the tests should be technology agnostic, i.e. they should not need to know about the underlying tech stack, which in this case is RxJava. The cases you describe are more or less error cases and IMO unit tests are best suited for these scenarios. Use Cucumber to test "one level higher" i.e. the components that use these Observables returning data. Use mocks to setup the appropriate start data
    – kaskelotti
    Nov 14 at 19:04















I think you are planning your tests on the wrong level. Cucumber should be used for testing the domain level of your application in such a manner that a business analyst can understand your tests. At best, the tests should be technology agnostic, i.e. they should not need to know about the underlying tech stack, which in this case is RxJava. The cases you describe are more or less error cases and IMO unit tests are best suited for these scenarios. Use Cucumber to test "one level higher" i.e. the components that use these Observables returning data. Use mocks to setup the appropriate start data
– kaskelotti
Nov 14 at 19:04




I think you are planning your tests on the wrong level. Cucumber should be used for testing the domain level of your application in such a manner that a business analyst can understand your tests. At best, the tests should be technology agnostic, i.e. they should not need to know about the underlying tech stack, which in this case is RxJava. The cases you describe are more or less error cases and IMO unit tests are best suited for these scenarios. Use Cucumber to test "one level higher" i.e. the components that use these Observables returning data. Use mocks to setup the appropriate start data
– kaskelotti
Nov 14 at 19:04

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247796%2fwriting-cucumber-scenarios-for-reactive-code%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247796%2fwriting-cucumber-scenarios-for-reactive-code%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3