BDD tests for Hadoop with Cucumber. Part II
In previous part we have created the application to process the data and docker container to isolate testing environment.
Acceptance tests, usually, check the normal behaviour of application - we want to be sure that the app do what is designed to do.
Gherkin is the great way to create acceptance tests - because it allows to concentrate on what we are going to do instead of how we do it, and, as a side effect, we get document features and scenarios in human-readable format which is very helpful, especially for new team members.
Our application should sort the data to the different folders regarding to caller countries, so let’s check it.
To do that we need to create folders for cucumber features:
src -> test -> resources -> features -> callstream
Lets create a new file
folder_structure.feature for the feature inside
At this point we don’t check the output data files format, only the folders structure.
To clarify that we should create understandable and clear feature description in terms of Gherkin:
Now we can write first ‘happy case’ scenario:
Assume we have an input data file with one caller from Ukraine:
I don’t include other data fields, because we will use default ones. Then we should run the processing job.
And check that job create the correct folder structure:
And, of course, it should contain file with processed data:
And, in summary:
It’s important to wrote these steps before implementation, so we will not limit our mind with details of our tests implementation.
After creation of scenario, we should create implementation of each step of the scenario.
Implementation for steps lives in
src -> java -> com -> steps folder.
For our callstream feature we should create
callstream folder and add
FolderStructureSteps.java into it.
Implementation of steps looks like that (I will not provide whole class here, it’s too large, and it’s not necessary to provide it here.
You can take a look in article repository for more) :
So, it is pretty simple - we match step string to the java regular expression in give/when/then annotations and wrote step implementation.
For data fixture generation we use simple template generator
themes folder for templates, so we habe to create folder in
themes in test resources and add
calls_log.chtml template with content:
As you can see we use default values for fields, which keep our scenarios in Gherkin clean and readable.
Now we have a basic test structure for acceptance tests and everyone can extend the test suite and include output content checks or other important things.
Full code of the project you can find here: https://github.com/savvyclutch/bdd_test_hadoop