Maven 2多模块pom

发布于 2024-09-26 03:11:42 字数 562 浏览 8 评论 0原文

我最近开始将我的项目从 ant 迁移到 Maven。我的应用程序中有两个模块,我可以使用 Maven 构建它们。

现在我有一个自动化测试项目,它使用 Web Driver 来测试 UI 功能。我试图使用maven 构建两个模块wars 并将它们部署到tomcat 上。然后针对它们运行自动化测试,如果自动化测试通过,则通过构建。我已经像这样配置了我的 pom(仅提到重要部分):

<packaging>pom</packaging>
<modules>
        <module>../module1</module>
        <module>../module2</module>
</modules>

现在两个项目都已构建和部署,但它不运行自动化测试。我想到的原因是封装类型是POM。但如果我将其更改为战争,它就会开始抛出错误。

我可以考虑创建第三个 pom 来实现自动化,并创建父 pom 将其也包含为模块。但我在想这是否是一个正确的方法。这应该是一个很常见的场景,maven 应该直接支持它。

I have recently started migrating my project from ant to maven. I have two module in my application which I am able to build using maven.

Now I have automated tests project which use Web Driver for testing UI functionality. What I am trying to do using maven is to build both module wars and deploy them on to tomcat. Then run automation tests against them and pass the build if automation test passes. I have configured my pom like this(just mentioning important part):

<packaging>pom</packaging>
<modules>
        <module>../module1</module>
        <module>../module2</module>
</modules>

Now Both the projects get build and deploy but It doesn't run automation tests. The reason I thought is that packaging type is POM. But If I change it to war it starts throwing error.

I can think of creating third pom for automation and parent pom to include that as module also. But I am thinking whether this is a right way. It should be a very common scenario and maven should be supporting it directly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╄→承喏 2024-10-03 03:11:42

(...) 自动化模块是基于 WebDriver 的自动化测试,用于测试 UI。它依赖于网络战争,但没有包依赖。我正在使用 Cargo Maven 插件部署到 tomcat。我想在运行自动化测试之前从源代码动态构建网络战争,然后部署到 tomcat 上,然后运行测试。我可以使用 ant build 完成所有这些工作,但无法使用 maven

这绝对是可行的(而且我已经做过很多次了)。但我不确定您当前的项目结构(特别是测试所在的位置)。

以下是我建议的结构:

.
├── functests
│   ├── pom.xml            // here we configure maven to run cargo & it tests
│   └── src
│       └── it
│           ├── java
│           │   └── ...    // functional tests will go here
│           └── resources
├── pom.xml                // aggregating pom
└── mywebapp               // the application under test
    ├── pom.xml
    └── src
        ├── main
        │   ├── java
        │   ├── resources
        │   └── webapp
        └── test
            ├── java
            └── resources

有关 pom 设置的详细信息,请查看 功能测试Maven、Cargo 和 Selenium,它包含所需的所有详细信息。

(...) automation module is the WebDriver based automation tests for testing UI. It depends on web war but there is no package dependency. I am deploying to tomcat using cargo maven plugin. I want to build web wars from source, on the fly just before running the automation tests, then deploy on tomcat and then run tests. I can do all these using ant build but unable to using maven

This is definitely doable (and I've done it numerous time). But I'm not sure to understand your current project structure (especially, where the tests are located).

Here is the structure I suggest:

.
├── functests
│   ├── pom.xml            // here we configure maven to run cargo & it tests
│   └── src
│       └── it
│           ├── java
│           │   └── ...    // functional tests will go here
│           └── resources
├── pom.xml                // aggregating pom
└── mywebapp               // the application under test
    ├── pom.xml
    └── src
        ├── main
        │   ├── java
        │   ├── resources
        │   └── webapp
        └── test
            ├── java
            └── resources

And for the details of the pom setup, have a look at Functional testing with Maven, Cargo and Selenium, it contains all the details required.

鸵鸟症 2024-10-03 03:11:42

我不认为带有共享集成测试模块的 2 个 war 模块是非常常见的场景。

但是,您可以使用 Hudson 来实现此功能。

  • 在 Hudson 中设置一个作业来部署您的父级别 pom,这将导致 war 模块按照您当前的方式进行部署。
  • 上一个作业成功后,触发另一个作业来运行集成测试。

您可能需要使用配置文件来激活集成测试,或更多特别是为了防止在第一个作业期间执行集成测试。

今年早些时候,我在大约一个小时内设置了一个基本的 Hudson 服务器。
Hudson 直接支持 Maven 构建,还为您的项目提供了一个位置 Maven 站点,包括所有质量报告等。
您还可以将 Hudson 配置为“监视”您的 SCM,并在识别到提交时启动构建。

I don't think that 2 war modules with a shared integration test module is a very common scenario.

However, you could get this working with Hudson.

  • Set up a job in Hudson to deploy your parent level pom, which will result in the war modules being deployed as you currently have.
  • On success of the previous job, trigger another job to run the integration-tests.

You may want to use profiles to activate integration testing, or more specifically to prevent integration tests from being executed during the first job.

I have earlier this year set-up a basic Hudson server in roughly an hour.
Hudson has direct support for maven builds and also provides a location for your projects maven site, including all of the quality reports etc.
You can also configure Hudson to "watch" your SCM, and initiate a build when it identifies a commit.

俏︾媚 2024-10-03 03:11:42

“我可以考虑创建第三个 pom”
你只有两个 POM 吗?每个项目/模块都需要自己的 POM。

请在此处查看有关使用 Maven 进行集成测试的更多信息:http://docs。 codehaus.org/display/MAVENUSER/Maven+and+Integration+Testing

编辑:
我不明白你的项目布局到底是什么样的。但我想它应该看起来像这样:

文件结构

myWebApp/
    pom.xml
    myWebApp-web/
        pom.xml
    myWebApp-integration-tests/
        pom.xml

/myWebApp/pom.xml

<packaging>pom</packaging>
<modules>
    <!-- packaging: war; here are the sources and unit tests -->
    <module>myWebApp-web</module>

    <!-- packaging: java; here are the integration tests -->
    <module>myWebApp-integration-tests</module>
</modules>

通过此设置, /myWebApp/mvn deploy 将执行以下步骤:

  1. 构建根项目(不执行任何操作,因为有没有源)
  2. 构建 myWebApp-web
  3. 部署 myWebApp-web (必须在 /myWebApp/myWebApp-web/pom.xml 中配置)
  4. 在 myWebApp-integration-tests 中执行测试

这应该可以满足您的要求。

"I can think of creating third pom"
Do you have only two POMs? Each project/module needs its own POM.

Look here for more information on integration tests with maven: http://docs.codehaus.org/display/MAVENUSER/Maven+and+Integration+Testing

Edit:
I don't understand exactly what your project layout looks like. But I guess it should look somehow like this:

File structure

myWebApp/
    pom.xml
    myWebApp-web/
        pom.xml
    myWebApp-integration-tests/
        pom.xml

/myWebApp/pom.xml

<packaging>pom</packaging>
<modules>
    <!-- packaging: war; here are the sources and unit tests -->
    <module>myWebApp-web</module>

    <!-- packaging: java; here are the integration tests -->
    <module>myWebApp-integration-tests</module>
</modules>

With this setup, /myWebApp/mvn deploy will execute the following steps:

  1. Build the root project (does nothing, as there are no sources)
  2. Build myWebApp-web
  3. Deploy myWebApp-web (has to be configured in /myWebApp/myWebApp-web/pom.xml)
  4. Execute tests in myWebApp-integration-tests

This should do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文