首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven多模块项目中客户端服务器应用程序的集成测试

Maven多模块项目中客户端服务器应用程序的集成测试
EN

Stack Overflow用户
提问于 2015-06-08 12:44:08
回答 2查看 1.5K关注 0票数 9

我有一个由几个模块组成的项目,这些模块使用maven,并自动上传并部署到运行构建及其测试的Jenkins应用程序中。

例如,有一个API模块、一个服务器和一个客户机。

客户端和服务器都使用API作为依赖项,以便能够正确工作。客户端通过正常使用的HTTP连接到服务器的web服务。

为了能够正常工作,服务器需要在Jetty上运行。

我有单元测试,通过使用模拟的HTTP请求调用服务器的功能来测试客户端。

我希望能够进行一些集成测试,例如测试两个实体之间的HTTP (和HTTPS)连接,测试超时等,以及在不诉诸模拟请求的情况下再现单元测试,以更接近实际的用例。

似乎这样的事情应该是容易做的,但我无法找到一种简单的方法,以一种可以被自动化的方式。

例如,在IDE中手动测试是通过单击服务器项目上的"run“和我的应用程序上的”运行测试“来完成的。

有没有一种方法可以在Jenkins中复制这个简单的过程,以便通过Maven配置甚至Jenkins插件自动完成?

更新:

我正在尝试制作另一个模块,它将使用我的服务器打包产生的war,并使用Jetty运行它。由于我的服务器的Jetty配置非常复杂,使用了由Maven过滤的Spring和https配置,因此在我的新模块中,由于缺少类和相关路径无法在这个上下文中工作,所以我遇到了一些问题。

是否有可能像在另一个模块中开始的那样运行这场战争而不跳过重复的资源和其他肮脏的技巧呢?

关于信息,我的pom.xml中特定的Jetty部分是:

代码语言:javascript
复制
<configuration>
                    <contextHandlers>
                        <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                            <war>${project.parent.basedir}/cmp-service/cmp-webapp/target/cmp-webapp-1.0-SNAPSHOT.war</war>
                            <contextPath>/cmp</contextPath>
                            <persistTempDirectory>true</persistTempDirectory>
                            <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
                        </contextHandler>
                    </contextHandlers>
</configuration>

更新2 :

我成功地构建了一个启动jetty并使用这个pom.xml运行集成测试的功能模块。

代码语言:javascript
复制
<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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>parent</artifactId>
        <groupId>com.project.test</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.project.test.integration-testing</groupId>

    <artifactId>integration-testing</artifactId>
    <packaging>jar</packaging>

    <name>integration-testing</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.0.M2</version>
                <configuration>
                    <contextHandlers>
                        <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                            <war>
                                ${project.parent.basedir}/myserver/myservice/target/myservice-${project.parent.version}.war
                            </war>
                            <contextPath>/cmp</contextPath>
                            <persistTempDirectory>true</persistTempDirectory>
                            <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
                        </contextHandler>
                    </contextHandlers>

                    <contextXml>
                        ${project.parent.basedir}/myserver/myservice/src/test/resources/jetty/jetty-context.xml
                    </contextXml>
                    <jettyXml>
                        ${project.parent.basedir}/myserver/myservice/src/test/resources/jetty/jetty.xml,${project.parent.basedir}/myserver/myservice/src/test/resources/jetty/jetty-ssl.xml,${project.parent.basedir}/myserver/myservice/src/test/resources/jetty/jetty-http.xml,${project.parent.basedir}/myserver/myservice/src/test/resources/jetty/jetty-https.xml
                    </jettyXml>
                    <systemProperties>
                        <systemProperty>
                            <name>scsf.configuration.file</name>
                            <value>
                                ${project.parent.basedir}/myserver/myservice/src/main/resources/config/cmpserver.properties
                            </value>
                        </systemProperty>
                        <systemProperty>
                            <name>org.eclipse.jetty.annotations.maxWait</name>
                            <value>180</value>
                        </systemProperty>
                    </systemProperties>
                    <systemPropertiesFile>
                        ${project.parent.basedir}/myserver/myservice/src/main/resources/config/cmpserver.properties
                    </systemPropertiesFile>
                    <daemon>true</daemon>

                    <stopKey>STOP</stopKey>
                    <stopPort>10001</stopPort>
                </configuration>
                <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                            <scanIntervalSeconds>0</scanIntervalSeconds>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
       ...
    </dependencies>
</project>

您也需要将依赖性添加到war中。

但是(总是有一个但)在运行验证目标时有一个问题。当我在我的集成测试模块中运行验证时,它有点工作。但是,当我在父程序中运行验证目标时,它应该调用与我的集成测试模块完全相同的验证目标(如果我正确理解它是如何工作的),一些路径将被不同的对待,并被解析为父/src/.而不是父母/整合-测试/src.

在从父级运行我的目标时,执行的上下文似乎会发生变化,并导致我的应用程序在寻找资源等时中断。

对于整个过程是如何工作的,有什么我不明白的吗?有没有办法让它工作?

更新3

我决定把我所有的道路都变成绝对的道路,这是可行的,但它不能解释这种行为。

EN

回答 2

Stack Overflow用户

发布于 2015-06-17 07:09:44

你自己已经知道了基本的步骤:

Stephen,一位maven开发人员,已经在堆栈溢出上写了一个关于这个主题的伟大的答案

我不太了解jetty-maven插件,但似乎不支持部署现有的工件。指定相对路径或绝对路径是绝对不可行的。您可能应该使用cargo来部署到jetty。货物配置可能如下所示:

代码语言:javascript
复制
<configuration>
  <configuration>
    <type>runtime</type>
    <properties>
      <cargo.hostname>testserver</cargo.hostname>
      <cargo.servlet.port>8080</cargo.servlet.port>
    </properties>
  </configuration>
  <container>
    <containerId>jetty9x</containerId>
  </container>
  <deployables>
    <deployable>
      <groupId>your.group.id</groupId>
      <artifactId>your-war</artifactId>
      <type>war</type>
      <properties>
        <context>/cmp</context>
      </properties>
    </deployable>
  </deployables>
  <deployer>
    <type>remote</type>
  </deployer>
</configuration>

货物单据有更多的细节。

hth,

  • 马丁
票数 1
EN

Stack Overflow用户

发布于 2015-06-11 01:42:50

你好杰伊

如果你真的想简化这里的事情,你为什么不连续地管理这些工作呢?首先是使用Maven进行编译、单元测试和部署任务。对于集成测试,创建另一个使用Selenium (用于web应用程序)和JMeter (用于web服务)等插件的工作。您还可以尝试其他许可证测试套件,如Openscript。

web服务测试将是棘手的,因为您的web服务使用者运行在另一个客户端上。在客户端应用程序上运行从代理吗?如果你有一个,在奴隶里面运行那些任务。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30709530

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档