Test Framework Refactoring
Writing tests in Behaviour Driven Development(BDD) mantra means ensuring everyone involved with application features being developed are on the same page. I am currently working on testing some APIs with tests already written in Java and I have been tasked with presenting a BDD Proof-Of-Concept (POC) to the team as a good way to tests the APIs. Here’s a summary of what I am using to accomplish that task:
- Â Java
- Â Ant
- Â Junit/TestNG
- Â Cucumber
- Â Intellij IDEA Ultimate version
- Â Jenkins
- Â Git/Github
Project Tasks
The list of main tasks include:
- Â Separate test data from tests
- Â Make tests extensible
- Â Clean-up existing tests – in short code re-factoring
- Â Introduce BDD into existing and future tests
- Â Categorize/Annotate tests for selective running purposes
The current development environment uses Ant and not Maven, which I would have preferred, but Ant is fast and it is already in the system – deep deep :). Â The Junit/TestNG thing is a result of the test annotation and categorization task. Â Currently using Junit but the extra features in TestNG has made it more appealing. Â This task is going to be the last step, to be honest and I am not very bothered about it at the moment.
State of Play
The existing tests are sufficient in ensuring a quick feedback if anything breaks in the system. Â The API provides services to many regions (US, Europe, the Middle East and Africa, Â Asia and the Pacific) and it is extremely important that the tests/monitoring systems give alerts if any part of the system/region is not responding as expected.
In getting the user stories (in .feature files) into existing test, writing the features, scenario outline and examples was not difficult. Â The challenge I am faced with is ensuring that data in the “Examples” section of the feature files, are used in step definitions taking advantage of existing test methods.
Searching online for a good tutorial on getting data from datatables (cucumber) into Java tests was not fruitful hence I had to find a solution. Â found a few links but the most helpful was from cukes.info itself.
Sample code:
@nightly
Feature: Car deals returned
Scenario Outline: Ensure that latest car finance deals are returned
Given the car deals api is available
When a valid request is made via the api
Then the api call should be successful with httpStatus OK
And the api response should have deals <response_key> and <response_value>
| response_key | response_value |
| location | |
| userGender | |
| selectCar | |
| selectFinance | |
Examples:
| location | userGender   | selectCar | selectFinance |
| london  | female        | bmw      | racket |
| berlin   | male          | mercedes | grapes |
| paris    | male          | audi       | orange |


0 Comments