In my last post on ATDD, we had seen how it was easy with Cucumber to write a feature file and share it with our stakeholders in order to validate our understanding of the functionality. The idea again is to build the right software right. In this post, we would learn how to do ATDD with ScalaTest but before that let us do a recap of what we learnt
Acceptance Test Driven Development (ATDD) is a practice in which the whole team collaboratively discusses acceptance criteria, with examples, and then distills them into a set of concrete acceptance tests before development begins. If you notice the keywords here then they are
- whole team discussion
- acceptance criteria
- with examples
- concrete acceptance tests
- before development begins
The last post would give you enough information for getting started with Cucumber. However, if you are in a (most likely) situation where your stakeholders would rather validate the output of acceptance tests for you AND you would rather not add another framework to your existing stack then you might be interested in Acceptance Testing with our trusted ScalaTest. You can read more about ScalaTest here.
Again, if you recollect from the last post. We have a feature. Every feature has scenarios (which includes the happy path and alternate paths).
For all such scenarios we would specify the
The corresponding mapping in the feature file scenario would be
Precondition == Given, And
Input == When
Let us see how we would write something like this using ScalaTest. We would use exactly the same example that we used in the Cucumber post, which is
Now let us see how we write it using ScalaTest and FeatureSpec
As you would notice, we are doing exactly what we were doing with Cucumber with the exception that we are not writing a feature file first. We are actually writing the feature file as a part of the Test. The output of this test would be something which would be interesting to the stakeholders.
Let us run the test with
The output that we get is
Had the output gone bad, meaning that say we were expecting 11 instead of 12 then we would get the result like this
Thus looking at the output the stakeholders would be able to verify whether the functionality has been implemented correctly or not. The code for the current blog is present on the Knoldus Github account. In our next post we would look like some goodies like how to pass multiple values to a single scenario. Without that we would have to keep repeating scenario definitions which violates DRY (Don’t repeat yourself). Till then.
2 thoughts on “ATDD, ScalaTest and Scala3 min read”
Reblogged this on Agile Mobile Developer.
Comments are closed.