开发者

How to integrate soapUI with Jenkins?

开发者 https://www.devze.com 2023-03-19 03:19 出处:网络
Anyone know a good 开发者_StackOverflow中文版way to add soapUI tests to my CI builds ?soapUI offers test automation via Maven or Ant. Maven integration is described HERE.

Anyone know a good 开发者_StackOverflow中文版way to add soapUI tests to my CI builds ?


soapUI offers test automation via Maven or Ant. Maven integration is described HERE.

I tried it some month ago but had some strange issues with the eviware repository... Therefore I run my tests now via Ant. What you have to do is to call the testrunner.bat (or testrunner.sh) script in the soapUI bin directory. You can find the available arguments HERE.

You have to install soapUI on your Hudson build server. Then you simply create a new job which is built via Ant.

Sample build.xml:

<project name="IntegrationTest" default="soapui-tests" basedir=".">
    <description>Runs the soapUI integration tests</description>
    <property file="build.properties"/>

    <target name="checkos">
        <condition property="testrunner.cmd" value="${soapUI.home}/bin/testrunner.bat">
                <os family="windows" />
        </condition>
        <condition property="testrunner.cmd" value="${soapUI.home}/bin/testrunner.sh">
                <os family="unix" />
        </condition>
    </target>

    <target name="soapui-tests" depends="checkos">
        <exec executable="${testrunner.cmd}"
              failonerror="yes"
              failifexecutionfails="yes"
        >    
            <arg value="-e ${service.endpoint}"/>
            <arg value="-P dbUrl=${db.Url}"/>
            <arg value="-rajf"/>
            <arg path="${report.dir}"/>
            <arg path="${soapui.project.folder}"/>
        </exec>
    </target>
</project>


It is quite simple...

Create a git repo with the following (example):

├── pom.xml
├── RestAPI-negativeTestSuite.xml
└── RestAPI-positiveTestSuite.xml

pom.xml, adjust where needed:

<project
        xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <name>Test soapui</name>
    <groupId>tdrury</groupId>
    <artifactId>com.example.soapuitests</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <description>blah blah</description>
    <build>
        <plugins>
            <plugin>
                <groupId>com.smartbear.soapui</groupId>
                <artifactId>soapui-maven-plugin</artifactId>
                <version>5.0.0</version>

                <executions>
                    <execution>
                        <id>RestAPI-positiveTestSuite</id>
                        <configuration>
                            <projectFile>RestAPI-positiveTestSuite.xml</projectFile>
                            <outputFolder>target/surefire-reports</outputFolder>
                            <testSuite>Positive cases</testSuite>
                            <junitReport>true</junitReport>
                            <exportwAll>true</exportwAll>
                            <printReport>true</printReport>
                            <testFailIgnore>true</testFailIgnore>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                    </execution>

                    <execution>
                        <id>RestAPI-negativeTestSuite</id>
                        <configuration>
                            <projectFile>RestAPI-negativeTestSuite.xml</projectFile>
                            <outputFolder>target/surefire-reports</outputFolder>
                            <testSuite>Negative tests</testSuite>
                            <junitReport>true</junitReport>
                            <exportwAll>true</exportwAll>
                            <printReport>true</printReport>
                            <testFailIgnore>true</testFailIgnore>
                        </configuration>

                        <goals>
                            <goal>test</goal>
                        </goals>

                        <phase>test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Create a new Maven job in Jenkins and point it to the git repo and pom.xml, as goal fill in test

That's all folks


The following script is invoked as part of a custom build script within hudson passing it the name of the target host to invoke the tests against.

#!/bin/bash -x

#
#   Regression Test Script for performing regression testing
#   
#   Note: Caution should be exercised where more than one set
#   of test suites exist in the same soapui project
#
#   Script invokes SOAPUI testrunner to perform tests
#
#   Script arguments:
#       target host
#

if [ $# -ne 1 ];
then
    echo "Usage: $0 target_host"
    exit 1
fi
TargetHost=$1
curdir=`pwd`
ProjectFile=$curdir/testing/SoapUI/YourProject.xml
SOAPUI_HOME=/soapuipath/soapui
TEST_RUNNER=testrunner.sh

if [ ! -f "$ProjectFile" ];
then
    echo "Project File does not exist"
    exit 1
fi
###############################################################################################
## Check the status of the last shell operation and if failed exit
###############################################################################################

## --------------------------------------------------------------------------------
##  Return the operating system pathname for the datafiles for the specified database
##
##  Arguments:
##      The return value to check.  zero indicates all is good.  Non-zero indicates error
##      The error message to display when exiting
##      
##  Exits if error detected
check_status()
{
    if [ $# -ne 2 ];
    then
        echo "$0: Programming error: Report to sysadmin@yourdomain.com"
        exit -1
    fi
    exit_code=$1
    err_msg=$2
    if [ $exit_code -ne 0 ];
    then
        echo $err_msg
        exit $exit_code
    fi
}


cd $SOAPUI_HOME/bin
bash -x ./$TEST_RUNNER -s"TestSuite 1" -c"TestCase 1 - Sanity Tests" -ehttps://$TargetHost:port/testurl "$ProjectFile"
check_status $? "Failed to pass regression testing "

cd "$curdir"


Why not use the JUnit integration? http://www.soapui.org/Test-Automation/integrating-with-junit.html

Edit: we had some weird performance numbers using this method (seconds instead of msecs), turns out it was because of using the SoapUI Runner. Running the same load test in SoapUI gave a correct result. Maybe we didn't use the API correctly (although it seems straightforward). We switched to using ContiPerf2 and using the client code (which we have to generate anyway) to run the tests and get normal results now.


I use the soapui-extension maven plugin - It is much better than the official Maven plugin. It's just the matter of configuring it to produce JUnit style results so that jenkins can pick them up.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号