Wednesday, November 29, 2017

Running SoapUI Test Cases with Maven

So, you have developed your software and you've done the right thing by creating your tests in SoapUI and they're all running smoothly. Now it's time to make the next step: make sure that your tests can be run automatically, preferably on different environments, for example every night or after a deployment. This is a major improvement in your continuous integration and delivery efforts, but how can this be achieved? In this blog, I will show how it can be done by using Maven, which can then again be used in for example Bamboo, Jenkins or any other continuous integration tooling.

With Maven, you basically just need a POM and a command to kick things off. In this example, we are using SoapUI 3.5.0, which is the latest open source version, Maven 3.5.2 and (since we need Java) JDK 1.8.0_131, but any other recent version will do as well.

Now, before we begin, if you use any JDK 1.8.x version, you need to copy a jar file named "jfxrt.jar" from ..\jdk1.8.0_131\jre\lib\ext into the ..\jdk1.8.0_131\jre\lib folder to make things work. If you resist, you will get a nasty error message and your test will not run with Maven. This obviously also applies to your continuous integration server.

Once you're setup, you will need to create a pom.xml file like the one below. You can place it in the same folder as your actual SoapUI test, but if you prefer to put it elsewhere, that's fine too. Just make sure to adjust the path to the SoapUI test then and be aware of differences between Windows and Linux environments (forward and backward slash). This is why I prefer to put the POM in the same folder as the SoapUI project.

Now there are several important elements here that you need to change for your own testing:
1. projectFile: the location plus name of your SoapUI project. Don't forget the .xml extension.
2. testSuite: the TestSuite that you want to be executed. If you leave it out, all TestSuites will be run.
3. testCase: the TestCase that you want to be executed. If you leave it out, all TestCases will be run within the specified TestSuite.
4. projectProperties: here you can manipulate the Custom Properties in your SoapUI project. Very useful for environment settings, for example.

Once you have the POM in place, you can navigate to its folder with command line, powershell or whatever tool you use and execute the following command:

mvn com.smartbear.soapui:soapui-maven-plugin:5.3.0:test -Denv=localhost

So, in the sample above, I have chosen to test my local environment by entering the value "localhost" into my Custom Property called "Env".

You might see some harmless error messages now, but they will not stop the test from running adequately. If you want to get rid of these, navigate to C:\Users\[Your User]\.soapuios\plugins and remove all files from there.

Once you run the test project like this, it will go through the specified TestSuite and TestCase, performing all the TestSteps in those and reporting on all the assertions. In the end, you'll get a BUILD SUCCESS or BUILD FAILURE message, depending on whether the result of the test matches the expectations set in your assertions.

Now you are ready to use the same command from your continuous integration tooling, decide when it should be run and which environment should be triggered.

No comments:

Post a Comment