Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is quite a lot of overhead in using cucumber for unit testing. Not only you have to write the features but then map them to the implementation using a separate bit of code.</p> <p>Unit testing is meant to be very fast to write and very fast to execute. Naturally, cucumber focuses on end user experience, mainly due to the language used in writing a feature.</p> <p>Just to refresh, a feature would contain the following:</p> <blockquote> <p><em>As some stakeholder of a system<br> I would like to perform an activity<br> So that I can get some benefit out of it</em></p> </blockquote> <pre><code>Given a precondition When I perform an action Then something should happen </code></pre> <p>The opening paragraph, that is often ignored, is very important as it sets a context for the operation and explains <em>why</em> something happens. Because of the use of natural language, these things are easy to show to non-programmers in order to get some feedback.</p> <p>Now, using these for unit tests would seem awkward at best. First of all, the end user focus suggests a more integration approach as the feature says nothing about mocks and UI/logic separation. I.e. a feature like the following just seems weird:</p> <pre><code>Given a that a database mock is configured with the following data | ID | Username | | 0 | igor | When call FindAll on User Repository Then I get the following user back | ID | Username | | 0 | igor | </code></pre> <p>Also, as your SUT gets smaller (i.e. a class), the context of operation is not as important. A User repository does not care about the context e.g. it doesn't care if the consumer of it is a normal user or a VIP user. A simple component (which it should be, following SRP), is completely deterministic based on its inputs.</p> <p>So, the unit test is there to validate that what you wrote is correct, and the cucmber test is there to validate that what you wrote satisfies some higher purpose by putting a behavior of the system in a context.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload