Integration Testing Locally and in the Cloud

Teams that develop larger applications will generally use integration testing and typically include tests that are executed against instances of the application running locally and in the cloud. The integration test process should therefore include the following steps:

  • Install the SAP Cloud Platform SDK for Neo environment
  • Install the local server runtime from the above SDK
  • Deploy and start the application locally
  • Deploy and start the application in the cloud
  • Run the integration tests locally and in the cloud
  • Stop the application in the cloud
  • Stop the application locally

This plugin will help you with most of the above. To get started, take a look at the snippet below and simply omit what you don't need:

    <project>
        [...]
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.sap.cloud</groupId>
                        <artifactId>neo-java-web-maven-plugin</artifactId>
                        <version>1.151.13</version>
                        <executions>
                            <execution>
                                <id>install-sdk</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>install-sdk</goal>
                                </goals>
                            </execution>
                            
                            <execution>
                                <id>local-setup</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>install-local</goal>
                                    <goal>deploy-local</goal>
                                    <goal>start-local</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>cloud-setup</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>deploy</goal>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            
                            <execution>
                                <id>cloud-teardown</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>local-teardown</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop-local</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <!-- Location of the SAP Cloud Platform SDK for Neo environment -->
                            <sdkInstallPath>${project.build.directory}/sdk</sdkInstallPath>

                            <!-- WAR of the application under test -->
                            <source>${project.build.directory}/${project.artifactId}.war</source>

                            <!-- Configuration for local server -->
                            <location>${sdkInstallPath}/server</location>

                            <!-- Configuration for cloud deployment -->
                            <host>${sap.cloud.host}</host>
                            <user>${sap.cloud.username}</user>
                            <password>${sap.cloud.password}</password>
                            <account>${sap.cloud.account}</account>
                            <application>${sap.cloud.application}</application>
                            <synchronous>true</synchronous>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        [...]
    </project>

Note: The use of the parameter properties (for example, for credentials) is optional, but it is generally good practice to use properties to inject this type of information dynamically.

Complex continuous integration (CI) scenarios will also require you to set ports for the local server runtime, in case multiple integration tests involving a local server runtime need to run at the same time. See, for example, the install-local goal and its parameters, such as httpsPort. Note that ports can be set statically or dynamically (see the Port Allocator Plugin for Jenkins, for example).

If your network is behind a firewall, you will need to configure the proxy. All goals support proxy configuration. See, for example, the deploy goal and its parameters, such as consoleHttpsProxyHost.

Tip: You might be interested in using the Maven Failsafe Plugin to actually run your integration tests in the integration-test phase.