End-to-End Setup and Integration of SoapUI with TestNG/JUNIT for API Testing
As testing requirements increase in cloud environments, automation becomes a need than a choice. Test automation enables engineering teams to improve execution efficiency, increases testing speed and faster time-to-market of product releases. SoapUI tool is one of the popular test automation tools used by experts to build a robust test automation framework. In this blog, we explore the best possible way to install and integrate SoapUI for building a test automation framework. We will also learn about the third-party reporting tools to create improved test reports after the integration.¬†
Before diving deep into SoapUI tool, let‚Äôs go through the basics of web services and API (Application Programming Interface). Now a days, most of the applications use web services or API to communicate between applications. APIs are more reliable, robust, secure and fast. Web service is a standardized way of communicating between a client and a server program using web protocols. Also, API does the streaming of operations.
Web services are a combination of states and protocols that assist us to validate request/response. With them, requests and responses can be transmitted forward and backward in a consistent way.
Why is There a Need to Test API Web Services/API?
As cloud computing continues to grow, APIs are needed for the interface and integration of one or more applications together on the web. API test automation helps reveal integration issues across the entire services or systems thus saving troubleshooting time and effort. ¬†
If any API fails due to any error, then not only does the single application fail but the entire dependant chain of applications will get affected. So, API should be tested before deployment in production or live scenarios.
Challenges of API Testing
The testing team faces several challenges while testing APIs like,
- Initial Setup of API Testing, updating the schema of API testing
- Testing parameter combination, validating parameters¬†
- Sequencing the API calls and tracking system integration
- There is no GUI for API¬†
To get the whole picture right away and accordingly, take immediate actions to apply fixes to the failures, you need tools which are capable of API testing. There are many automation tools available in the market for API testing. Most popular tools are SoapUI and Rest API.
Using SOAPUI Tool for API Testing
This tool is provided by, SoapUI org. You can get a free or licensed copy as per requirement.
SoapUI is the widely used Functional Testing tool for SOAP and REST API testing. With its easy-to-use graphical interface, and enterprise-class features, SoapUI allows you to rapidly create and execute automated functional, regression, and load test suite.
SOAP stands for Simple Object Access Protocol. It is an XML-based protocol for accessing web services. SOAP is used for communication between two applications. It is platform independent and language independent. By using SOAP, you will be able to interact with other programming language applications. SoapUI tool is testing tool for testing web services. It helps us to maintain framework and test suite of web services. ¬†
To validate any web service, you need WSDL (Web Services Description Language) file of project which is written in the XML format to access all the operations of that web service.
What‚Äôs an Automation Framework?
Automation Framework is not a single tool or process, but it is a collection of tools and processes working together to support automated testing of any application or APIs. It integrates a variety of tasks, such as libraries/utilities, reusable modules/methods and other kinds of test data.
Designing a Test Automation Framework:
The automation framework design is useful when there‚Äôs a need to run regression test suite or repeat test execution and to validate report. Let‚Äôs start building automation framework for API testing with SoapUI Tool.
- First install SoapUI tool from soapui.org
- Create New Soap Project & import the WSDL file path of your project and click on OK.
- Once the project is created successfully with WSDL, you will get all requests of your project imported from the WSDL file.
- Click on any request to check request details¬†
- To create Test Suite right click on project service and click on generate test suite (e.g. in the above image, services are CalculatorSoap or CalculatorSoap12 ‚Äď both having same requests, just CalculatorSoap12 is upgraded version)
- In this created TestSuite, you will get each test case with test-step for each request.
- Here in test cases you can see teststep where you can set input.¬†Once input is set, you can execute this testcase and validate response.
- For testcases, you can add multiple test steps, groovy script and JDBC request as well.
- Here your Project setup is ready with your testcases and testsuite.
Properties in SoapUI
Using Properties, you can set testdata outside request as local or global property and then, fetch this property in your request. Properties can be set at various levels like¬†
Project level, Testsuite Level, Testcase level and teststep level. Also, you can read testdata from eternal files like excel and properties file.
Below image describe the Framework structure having multiple testcases:
Once we set up our framework, this project is ready to integrate with TestNG/JUnit.
Next, let‚Äôs look at SOAP Project integration with TestNG, a process which is similar to integration with JUnit.
SOAP Project Integration with TestNG in Eclipse:
- To integrate your SOAP Project with TestNG, you need to install testNG plugin from eclipse marketplace.
- Then, create simple java project and create a Runner java class (eg. SoapRunner.java).
- In Runner class, first you need to set your SOAP Project path using object of wsdlProject
- Copy all SoapUI jar from lib and bin folder of SoapUI installed path and add in to eclipse build path as external library jar
- Now add your testcases using @Test annotation. (note: you can set priority for test execution)
- And final step is run TestNG. Xml to execute your all testcases of Runner class
Here you can see the SoapUI TestNG Project integration in Eclipse:
Console Output on Eclipse Editor:
SoapUI: Extent and CSV Report generation
After successful framework design and integration, we can generate Reports to format our testcases result in a more presentable format.
For reporting, many third-party tools are available. Here will see with 2 methods,
1. Extent Report
2. CSV/Excel Report
Extent Report: To generate Extent report in SoapUI you need to add report code script in teardown script of your project.
¬† ¬† ¬†
And you will get Extent HTML report as shown below:
CSV Report: To generate CSV report, you need to write one script and execute it from teardown script. Then, you will get CSV report in the below format:
Advantages of Soap UI Tool¬†
Want to discuss test automation using SoapUI?