WSO2 has a great suite of tools that can help us develop our integrations in an easy and robust way. However, there is no tool dedicated to Testing amongst those available. In this post, we will explore how we have approached this perspective from the point of view of Chakray, and how we can ensure the reliability of our developments with Cucumber.
How to Carry Out Functional Tests in the Development of Integrations
We must take into account that Testing (functional tests) is a very important phase in the development of integrations, and that there is no better way to demonstrate the proper functioning of our integration than a detailed test report. There, our client can verify that the proposed requirements have been carried out and that they are working perfectly.
Within the world of application Testing, there is an infinite amount of software programs which can help us, but not all of them produce a report or indicate precisely which tests have been carried out. That is why, at Chakray, we have chosen Cucumber.
What is Cucumber?
Cucumber is a BDD (behavior-driven development) testing software program which will allow us to elaborate unitary tests based on acceptance criteria, which can be easily understood by all those involved in the process. Through Cucumber, the analyst will be able to define a set of use cases in order to confirm the performed development. Each case will have its correlation with Cucumber scenarios, which will be implemented later in a programming language used by the quality or testing engineer.
Furthermore, we should not forget that BDD emerges from TDD (test-driven development). Therefore, this approach allows us to compare, at least in part, the development of integration with that of testing, which is another strong point to take into consideration.
Example of How to Define a Sase of Use
For a more detailed look, we will use an example of how an analyst defines a use case based on a customer requirement, and the quality engineer develops and executes the associated test. Let’s start with the analyst and their example case:
Test Case ID | CU01-DEV-001 |
Functionality | Create BOOK object via API |
ID Requirement | REQ-CU01-001 |
Description | We call the method of creating the BOOK object |
Preconditions |
|
Action | Expected Result |
We send a request with POST /library/bbdd/book | The service returns 202 and an empty payload
In the BOOK table there is a record |
Example of Test Development and Execution
The first step will be to create a .feature file where we will add all the test cases of our use case. For each test case, we will create a scenario within this feature file. This scenario will be the implementation of the analyst’s test case.
In the test case we will perform the following steps:
- Configure the request for the API we have developed and wish to test.
- Indicate how to make this call: the headers, payloads, etc.
- Carry out the call.
- Check the result: the code and payload of reply or associated elements (as it can be checked if in the database a record has been created).
Here we can see its translation into Gherkin language.
These files should be stored in a Java project. This will allow for the execution of the tests and the storage of all the necessary test files, such as the features or the attached files which allow us to perform such tests (such as the call payloads).
With this project, we will be able to run the tests through a simple maven command: mvn test. This is because we can run these tests through JUnit.
Here another of the advantages will become clear; that its execution is visually very smooth. We can see at a glance if everything has worked correctly or not. This would be a sample outing:
Cucumber Reports:
Then there is the report, which will comprise the detailed execution of all the tests that we have carried out as well as the results of those tests. We can also get this easily through Cucumber. In this report we will view:
- The tests we have carried out.
- The visualization of all the features, scenarios and steps associated with the tests.
- The information regarding its execution: what has been the result of execution, the time needed for execution, etc.
- The results display by means of graphs.
Here’s an example:
As you can see, Cucumber is a very interesting tool that will give us an advantage when carrying out our developments, and it will allow us to take our developments to the next level.