Category Archives: Testing

Test Automation and other related topics

Building smoke test harness to test Webservices using SoapUI

We are currently working on a large enterprise integration project. The Integration is developed on a Services Oriented Architecture(SOA), where each application exposes itself as a Webservices. We finished our development cycle and when we migrated the code from development to QA environment, it was very difficult to make sure all the webservices are up and giving a valid response, there were close to 200 services. Mostly the test was done manually.

We went back to the drawing board and analysed how we can automate this. SoapUI, JUnit, Maven and Jenkins came to our rescue. The goals of this implementation is as below,

  • Build SoapUI projects to verify if the services is up and it is responding with meaningful message and we assert the response
  • Parameterizing/externalizing the host name, username and password so that we can run the tests on any environments
  • This can be even tested against live data/production system, hence we should never modify any real data
  • Having a easy web interface to test the interfaces

SoapUI project

  • Create a SoapUI project and Add WSDL (Ctrl U), Create Request and Create a Test Suite, Create Test case and Test Step
  • Bind the webservice method to the Test Step
  • Hardcode the test values to the Test step
  • Assert the response by Adding an assert
  • If the Webservice needs authentication, and if you want to parameterize the user name and password, you need pass ${#Project#username} and ${#Project#password}
  • Finally save the project

JUnit and Maven

You need to create a Maven/Java project and add the below dependency

<dependency>
  <groupId>eviware</groupId>
  <artifactId>maven-soapui-plugin</artifactId>
  <version>4.5.0-SNAPSHOT</version>
</dependency>

In your junit class you need to write the below code,

public void testWebService() {
  SoapUITestCaseRunner runner = new SoapUITestCaseRunner();   runner.setProjectFile(soapUIProjectFile);
  String soapUIProjectFile = System.getProperty("soapUIProjectFile");
  String hostName = System.getProperty("hostName");
  String userName = System.getProperty("userName");
  String password = System.getProperty("password");
  if (hostName != null && hostName.trim().length() > 0) {
    runner.setHost(hostName);
  }
  String[] properties = new String[2];
  properties[0] = (password != null && password.trim().length() > 0) ? "pwd="     + password     : "";
  properties[1] = (userName != null && userName.trim().length() > 0) ? "username="     + userName     : "";
  runner.setProjectProperties(properties);
  runner.run();
  return runner.getFailedTests();
}

Integrating with Jenkins

Create a new Maven Jenkins job, and parameterize the above 4 values as below,

mvn -DsoapUIProjectFile=${soapUIProjectFile} -DhostName=${hostName} -DuserName=${userName} -Dpassword=${password}

2 points to note,

  • Make sure these parameters soapUIProjectFile, hostName, userName, password are created in the Jenkins
  • soapUIProjectFile are checked in the same unit test project and the relative path of the SoupUI project is provided in Jenkins

That is all needs to be done, once it is in place, you just need to run the Jenkins project, it will prompt you with this information, if you pass the values, it will test the webservices in that environment.

We can also enhance this to,

  • Test all the projects in a folder in a recursive way
  • Get meaningful message from junit to inform how many webservices have passed and how many have failed and why they have failed