5

I am wondering if it is possible to use cucumber(js) for BDD unit testing? Cucumber is known to be runable as a acceptance testing framework. But I have never seen examples if and how cucumber may be used as a BDD unit testing.

Is cucumber able to provide unit tests? Is it uncommon to use cucumber for unit testing?

cilap
  • 2,215
  • 1
  • 25
  • 51

2 Answers2

7

BDD is a process/mechanism for driving development by using high level descriptions of the the behavior of the application. Cucumber (in all its forms) is a tool for supporting this process by allowing you to specify high level concepts in a natural language that can be automated. It is not a tool for writing unit tests.

Cucumber is a tool for the outer circle of the BDD process

BDD two circles diagram

But as you can see BDD has an inner circle where unit testing takes place.

When you are in the inner circle sometimes you have to build things to make the outer circle green (other times you will just use existing things). When you build things you require unit tests. In the inner circle the level of abstraction is lower, the amount of detail is much greater, and exhaustive testing is much more important. These combine to make using cucumber for these tests prohibitively expensive and difficult. This is why unit testing tools are a better fit here.

diabolist
  • 3,990
  • 1
  • 11
  • 15
1

I think this is absolutely correct, please find examples here and here

Eugene
  • 1,865
  • 3
  • 21
  • 24
  • +1 from me. could you tell me what exactly you mean with "this is absolutely correct"? Do not get it from your answer to my questions. – cilap Feb 07 '15 at 18:24
  • Thanks @cilap, there is discussion if BDD is correct to use in the unit testing. One opinion that it's only for the system and integration tests. I support the position for widely using BDD. Please see this [link](http://guide.agilealliance.org/guide/bdd.html) from Agile Alliance where unit test is also the first class citizen. – Eugene Feb 07 '15 at 19:27
  • Eugene, do you have some examples of how unit tests are created with cucumber? I am just trying to find out, how the cucumber.js can be used without a html-client. Just for plain unit tests. – cilap Feb 09 '15 at 11:40
  • java would also be fine. – cilap Feb 09 '15 at 16:05
  • thank you, checked it. But I see you are always using the WebDriver of Selnium. So from my perspective it is more a acceptance test, since it automates some "human" work. I search more for the option, if cucumber is able to test for example some specific code - without any UI/Selenium. E.g. assume to test validation code of a specific input field, but on code level and not on UI level (without htmldriver/firefoxdriver) – cilap Feb 09 '15 at 17:06
  • can you now clarify your answer please? Since your last comments do not fit to your provided answer?!? I am now really confused. – cilap Feb 10 '15 at 12:29
  • I don't have something that I can to share. I would happy to help you . Could you please provide some Java class and I will try to show you possible unit test. – Eugene Feb 10 '15 at 20:29