Integration With Java Applications

Applies to ReadyAPI 3.56, last modified on November 21, 2024

To integrate ReadyAPI tests in your Java applications, add the ReadyAPI libraries to your project and then call the needed methods from your code.

ReadyAPI tests can also be run from popular test frameworks, such as JUnit or TestNG.

Prepare for Running ReadyAPI Tests

To prepare your application for running ReadyAPI tests, you need to import the ReadyAPI libraries to your project:

  • If you use Maven, add the following dependencies to your pom.xml file:

    XML

    <repositories>
        <repository>
            <id>SmartBearPluginRepository</id>
            <url>http://smartbearsoftware.com/repository/maven2</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.smartbear</groupId>
            <artifactId>ready-api-maven-plugin</artifactId>
            <version>2.7.0</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.olap4j</groupId>
            <artifactId>olap4j</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
    </dependencies>

-- or --

  • Manually import .jar files from the <ReadyAPI installation directory>\lib folder to your application project.

After that, you can use the ReadyAPI Runner classes to run your tests.

Available Classes

Your tests have access to the following classes:

Class Description
SoapUIProTestCaseRunner Contains methods you use to work with functional tests.
SoapUIProSecurityTestRunner Contains methods you use to work with security tests.
LoadUIProjectRunner Contains methods you use to work with load tests.
SoapUIMockServiceRunner Contains methods used to start and stop virtual APIs.

Starting Tests

To start your ReadyAPI tests, use the following code:

Java

import com.smartbear.ready.cmd.runner.pro.*;

public void Test() {
    try {
        // Create a test runner object
        SoapUIProTestCaseRunner runner = new SoapUIProTestCaseRunner();

        // Specify the path to the project file
        runner.setProjectFile("C://Work//sampleproject.xml");

        // Specify the test suite to run
        runner.setTestSuite("Test Suite 1");

        // Specify the test case to run
        // It must be in the test suite specified above
        runner.setTestCase("Test Case 1");

        // Command the runner to create a printable report
        runner.setPrintReport(true);

        // Start the test run
        runner.run();
    }
    // Handle the exception, if any
    catch (Exception e){
        e.printStackTrace();
    }

Reporting and Exporting Functional Web Service Tests

Runner classes support creating reports for a tests run. To do this, enable the option to create a report and set the report output folder:

Java

// Create the runner object
SoapUIProTestCaseRunner runner = new SoapUIProTestCaseRunner();

runner.setOutputFolder("C:\\Users\\mwl\\tmp")

// Run the test
// Command the runner to create JUnit-style report
runner.setJUnitReport(true);

// Command the runner to create printable report
runner.setPrintReport(true);

// Command the runner to open the created report
runner.setOpenReport(true);

// Specify the folder to save the report in
runner.setOutputFolder("C:\\Users\\mwl\\tmp")

// Run the test
runner.run();

Exported files have the following names: <TestSuite>-<TestCase>-<TestStep Name>-<Count>-<Status>.txt. They will appear in the report folder you have specified.

For example, you can have the following file: TestSuite 1-TestCase 1-Request Step 1-0-OK.txt. If you run the test step several times during the test case run, ReadyAPI will save each run as an individual file.

The response attachments will also appear in the report folder. They will have the following name template: <TestSuite>-<TestCase>-<TestStep Name>-<Count>-attachment-<AttachmentCount>.<Extension>. By default, they will have a format matching the content-type. If it is not available, ReadyAPI will save the attachment in .dat format.

See Also

Integrations
Integrations

Highlight search results