- 浏览: 802494 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (360)
- Java (101)
- JPA/Hibernate (10)
- Spring (14)
- Flex/BlazeDS (37)
- Database (30)
- Lucene/Solr/Nutch (0)
- Maven/Ant (25)
- CXF/WebService (3)
- RPC/RMI/SOAP/WSDL (1)
- REST (6)
- TDD/BDD/JUnit (1)
- Servlet/JSP (2)
- AI/MachineLearning (3)
- Resource (1)
- 字符编码 (2)
- OOA/OOPS/UML (5)
- DesignPattern (8)
- 算法与数据结构 (11)
- Web&App Server (13)
- 并发&异步&无阻塞 (7)
- Entertainment (4)
- JavaScript/ExtJS (45)
- CodeStyle&Quality (1)
- svn/git/perforce (8)
- JSON (2)
- JavaScriptTesting (4)
- Others (6)
- RegularExpression (2)
- Linux/Windows (12)
- Protocal (2)
- Celebrities (1)
- Interview (1)
- 计算机语言 (1)
- English (2)
- Eclipse (5)
- TimeZone/时区 (1)
- Finance (1)
- 信息安全 (1)
- JMS/MQ (2)
- XSD/XML/DTD (3)
- Android (4)
- 投资 (3)
- Distribution (3)
- Excel (1)
最新评论
-
qdujunjie:
如果把m换成具体的数字,比如4或者5,会让读者更明白
m阶B树中“阶”的含义 -
java-admin:
不错,加油,多写点文章
关于Extjs的mixins和plugin -
xiehuaidong880827:
你好,我用sencha cmd打包完本地工程后,把app.js ...
ExtJS使用Sencha Cmd合并javascript文件为一个文件 -
KIWIFLY:
lwpan 写道inverse = "true&qu ...
Hibernate中什么时候使用inverse=true -
luedipiaofeng:
good
消除IE stop running this script弹出框
参考文章:http://stackoverflow.com/questions/16935290/maven-deploy-webapp-to-tomcat-before-junit-test
There are a number of schools of thought as to how to handle this type of integration test with Maven.
I should point out that when you are deploying an application to an application server, you are not in the realm of unit testing any more. Because the entire application is being deployed within a container, you are testing the integration of those two components.
Now there is nothing wrong with using JUnit for running integration tests (though there are some limitations that you may hit, for example unit tests should not care about the sequencing of individual tests - assuming you are writing them correctly - so JUnit enforces this by not guaranteeing any sequence of execution... prior to Java 1.7 the execution order was accidentally implied by the order of test methods within a class, but it was not part of the JUnit contract... Some people switch to other testing frameworks for their integration tests, e.g. TestNG, if they find the unit test focus of JUnit is getting in the way of their test development)
The key point to keep in mind is that the Maven lifecycle uses the test phase for the execution of unit tests.
When it comes to integration tests there are two (and a half) schools of thought as to the right way to handle the tests with Maven.
School 1 - Failsafe and integration-test/verify
This school of thought uses the phases after package to start up a container, run the integration tests, tear down the container, and finally check the test results and fail the build in the event of test failures.
NEVER EVER RUN mvn integration-test as that will not tear down the container correctly, any time you think you want to type mvn integration-test you actually want to type mvn verify (oh look, it's shorter and easier to type also... bonus)
So with this you do the following:
Bind tomcat7:run to the pre-integration-test phase with fork=true
Bind failsafe:integration-test to the integration-test phase
Bind tomcat7:shutdown to the post-integration-test phase
Bind failsafe:verify to the verify phase.
For extra brownie points you would use build-helper-maven-plugin:reserve-network-port bound to the validate phase to ensure that the test server is started on an unused network port and then either use resource filtering against the test resources to pass the port through to the tests or use a system property passed through systemPropertyVariables to make the port number available to the tests.
Advantages
Clean Maven build
If the tests fail, you cannot release the project
Can move the integration tests into a separate profile (by convention called run-its) if the tests are too slow to run every build.
Disadvantages
Hard to run the tests from an IDE. All the integration tests start/end in IT and while Maven knows to run tests starting/ending in Test with Surefire and run tests starting/ending in IT with Failsafe, your IDE probably doesn't. Additionally, your IDE is not going to start the container for you, so you have to do a lot of work by hand to actually run the tests manually.
Debugging the tests potentially requires attaching two debuggers, e.g. one to debug the application running in container and the other to debug the test cases.
mvnDebug -Dmaven.failsafe.debug=true verify
Couples your tests to the Maven build process.
School 2 - Separate module
This school of thought moves the integration tests into a separate module that depends on the war module and copies the war into the test resources using, e.g. dependency:copy-dependencies bound to the generate-test-resources phase coupled with a Tomcat7 dependency to test against.
The test cases themselves start up the Tomcat7 container using embedded mode
Advantages
Tests can run in IDE
Integration tests are separated from Unit tests, so asking the IDE to run all tests will not kick off the slower tests
Disadvantages
The war artifact is only rebuilt if you go past the package phase, consequently, you need to run at least mvn clean package periodically to refresh the code under test when using the IDE.
The failure of the integration tests does not break the build of the war module, so you can end up releasing a broken war artifact and then have the reactor build fail for the integration test module. Some people counteract this issue by having the integration test module within src/it and using Maven Invoker Plugin to run the tests... though that provides a poorer IDE integration, so I do not recommend that line.
Hard to get a consolidated test coverage report from Maven.
Have to code the container start/stop yourself from within your test cases.
School 2.5 - Failsafe with the test cases starting their own Tomcat7 server
This is a kind of hybrid of the two approaches.
You use Failsafe to execute the tests, but the tests themselves are responsible for starting and stopping the Tomcat7 container that you want to test in.
Advantages
Don't have to configure the server start/stop in Maven pom
IDE can safely run all tests (though the integration tests may be slower and you may want to not run them, but it's not like they will all fail unless there is a test failure)
Easier to debug the tests from your IDE (only one process to attach against, and the IDE usually makes it easy to debug tests by providing a special test runner)
Disadvantages
Have to code the container start/stop yourself from within your test cases
I hope the above helps you understand the options you have. There may be other tweaks but in general the above are considered the best practice(s) for integration testing with Maven at present.
There are a number of schools of thought as to how to handle this type of integration test with Maven.
I should point out that when you are deploying an application to an application server, you are not in the realm of unit testing any more. Because the entire application is being deployed within a container, you are testing the integration of those two components.
Now there is nothing wrong with using JUnit for running integration tests (though there are some limitations that you may hit, for example unit tests should not care about the sequencing of individual tests - assuming you are writing them correctly - so JUnit enforces this by not guaranteeing any sequence of execution... prior to Java 1.7 the execution order was accidentally implied by the order of test methods within a class, but it was not part of the JUnit contract... Some people switch to other testing frameworks for their integration tests, e.g. TestNG, if they find the unit test focus of JUnit is getting in the way of their test development)
The key point to keep in mind is that the Maven lifecycle uses the test phase for the execution of unit tests.
When it comes to integration tests there are two (and a half) schools of thought as to the right way to handle the tests with Maven.
School 1 - Failsafe and integration-test/verify
This school of thought uses the phases after package to start up a container, run the integration tests, tear down the container, and finally check the test results and fail the build in the event of test failures.
NEVER EVER RUN mvn integration-test as that will not tear down the container correctly, any time you think you want to type mvn integration-test you actually want to type mvn verify (oh look, it's shorter and easier to type also... bonus)
So with this you do the following:
Bind tomcat7:run to the pre-integration-test phase with fork=true
Bind failsafe:integration-test to the integration-test phase
Bind tomcat7:shutdown to the post-integration-test phase
Bind failsafe:verify to the verify phase.
For extra brownie points you would use build-helper-maven-plugin:reserve-network-port bound to the validate phase to ensure that the test server is started on an unused network port and then either use resource filtering against the test resources to pass the port through to the tests or use a system property passed through systemPropertyVariables to make the port number available to the tests.
Advantages
Clean Maven build
If the tests fail, you cannot release the project
Can move the integration tests into a separate profile (by convention called run-its) if the tests are too slow to run every build.
Disadvantages
Hard to run the tests from an IDE. All the integration tests start/end in IT and while Maven knows to run tests starting/ending in Test with Surefire and run tests starting/ending in IT with Failsafe, your IDE probably doesn't. Additionally, your IDE is not going to start the container for you, so you have to do a lot of work by hand to actually run the tests manually.
Debugging the tests potentially requires attaching two debuggers, e.g. one to debug the application running in container and the other to debug the test cases.
mvnDebug -Dmaven.failsafe.debug=true verify
Couples your tests to the Maven build process.
School 2 - Separate module
This school of thought moves the integration tests into a separate module that depends on the war module and copies the war into the test resources using, e.g. dependency:copy-dependencies bound to the generate-test-resources phase coupled with a Tomcat7 dependency to test against.
The test cases themselves start up the Tomcat7 container using embedded mode
Advantages
Tests can run in IDE
Integration tests are separated from Unit tests, so asking the IDE to run all tests will not kick off the slower tests
Disadvantages
The war artifact is only rebuilt if you go past the package phase, consequently, you need to run at least mvn clean package periodically to refresh the code under test when using the IDE.
The failure of the integration tests does not break the build of the war module, so you can end up releasing a broken war artifact and then have the reactor build fail for the integration test module. Some people counteract this issue by having the integration test module within src/it and using Maven Invoker Plugin to run the tests... though that provides a poorer IDE integration, so I do not recommend that line.
Hard to get a consolidated test coverage report from Maven.
Have to code the container start/stop yourself from within your test cases.
School 2.5 - Failsafe with the test cases starting their own Tomcat7 server
This is a kind of hybrid of the two approaches.
You use Failsafe to execute the tests, but the tests themselves are responsible for starting and stopping the Tomcat7 container that you want to test in.
Advantages
Don't have to configure the server start/stop in Maven pom
IDE can safely run all tests (though the integration tests may be slower and you may want to not run them, but it's not like they will all fail unless there is a test failure)
Easier to debug the tests from your IDE (only one process to attach against, and the IDE usually makes it easy to debug tests by providing a special test runner)
Disadvantages
Have to code the container start/stop yourself from within your test cases
I hope the above helps you understand the options you have. There may be other tweaks but in general the above are considered the best practice(s) for integration testing with Maven at present.
发表评论
-
maven正确的持续集成命令-U -B选项
2017-08-06 09:40 1364原文:http://healthandbeauty.iteye ... -
maven命令行窗口指定特定settings.xml
2017-07-25 16:44 4019通过命令行方式执行mvn命令时如果不指定settings.xm ... -
Maven通用.project文件和.classpath文件
2017-06-08 10:22 1240.project <?xml version=&qu ... -
Maven划分模块
2016-07-15 16:38 692http://juvenshun.iteye.com/blog ... -
Karma和Jasmine自动化单元测试
2016-03-10 10:55 992原文链接:http://blog.fens.me/nodejs ... -
测试Angular应用的工具
2016-03-02 10:17 816参考https://docs.angularjs.org/gu ... -
Ant命令行参数传递
2015-10-19 17:54 1378ant run arg0 arg1 then ant woul ... -
maven传递依赖的版本确定规则
2014-06-12 18:05 1535原文链接: http://blog.csdn.net/blui ... -
dependencies 和 dependencyManagement
2014-06-12 17:01 824如果在父pom中使用了dependencies 和 depen ... -
Maven 重复依赖检测 (Dependency Convergence), 包冲突解决
2014-05-27 10:20 12742方法一 maven命令方式 详情参考: https://ma ... -
获取maven完整/实际/生效(effective)的pom.xml文件
2014-01-24 10:53 2926方法一 maven 命令行方式 mvn help:effec ... -
快速获取当前操作系统信息的maven命令
2014-01-14 10:22 1446mvn enforcer:display-info -
maven基于操作系统环境的构建
2014-01-14 10:16 882详情参考: http://maven.apache.org/e ... -
Maven中如何实现条件分支
2014-01-14 10:14 1416Ant中有condition表达式,maven中对应的是pro ... -
与Ant对应的Maven功能
2014-01-14 10:11 848Ant Expressions to Maven Expres ... -
Maven常用配置或命令
2013-09-18 14:28 1433Maven插件列表 https://maven.apache ... -
maven运行bat文件(批处理命令)
2013-09-11 15:06 8739maven install时,运行批处理命令的好处是,如果你需 ... -
Chrome开发者工具面板介绍
2013-06-26 13:59 15301.网络面板 Network 另外提供一篇介绍更全面的文档: ... -
maven scope含义的说明
2013-06-14 10:17 881依赖范围控制哪些依赖在哪些classpath 中可用,哪些依赖 ... -
Maven Integration for Eclipse vs. Maven eclipse:eclipse plugin
2013-04-25 13:58 1091Maven Integration for Eclipse v ...
相关推荐
Jmeter+Jenkins+maven 接口自动化集成测试框架 Jmeter+Jenkins+maven 接口自动化集成测试框架是一种自动化测试解决方案,旨在简化测试过程,提高测试效率和测试质量。该框架通过集成 Jmeter、Jenkins 和 Maven 三个...
在这个项目中,我们将利用JMeter、Jenkins和Maven三个强大的工具进行接口自动化集成,实现持续集成和自动化测试。 **JMeter** 是一个开源的性能测试工具,主要适用于Web应用的压力和负载测试,但也可以用于接口测试...
这个实例项目展示了如何将这四个强大的工具集成为一套完整的自动化测试解决方案。 **Java**: Java是一种广泛使用的面向对象的编程语言,以其跨平台的特性闻名,非常适合编写自动化测试脚本。在自动化测试中,Java...
文档《接口自动化-jenkins+maven+jmeter持续集成.pdf》详细介绍了如何利用Jenkins、Maven和JMeter这三个强大的工具,搭建一个完整的接口自动化测试和持续集成环境。 首先,文档提到了Jenkins的安装与配置,包括...
Jenkins作为CI/CD流水线的核心工具,能够与Maven、Git等工具无缝集成,帮助开发者实现自动化的构建、测试和部署流程。 #### 二、JDK安装 **1. 下载与安装** - **下载**: 访问Oracle官网下载适用于Linux系统的JDK ...
在自动化测试环境中,我们可以使用Eclipse和Maven来进行单元测试和集成测试。 3.1 运行单个单元测试 在Eclipse中,我们可以通过right-clicking单元测试类并选择“Run As”->“JUnit Test”来运行单个单元测试。 ...
自动化部署的核心在于构建一个稳定且高效的持续集成/持续部署(CI/CD)环境。为了实现这一目标,通常需要以下几项关键技术组件: 1. **JDK (Java Development Kit)**: - **作用**: JDK 是 Java 开发的基础,提供了...
标题中的“maven工程在tomcat服务器上的自动化部署”指的是使用Maven构建工具与Tomcat应用服务器相结合,实现Java Web项目自动部署的过程。这个过程旨在提高开发效率,减少手动部署的繁琐步骤,使得每次代码更新后都...
Maven自动化部署 Maven Web应用 Eclispe IDE集成Maven NetBeans IDE集成Maven Eclipse构建Maven项目 转换基于Maven的Java项目支持Eclipse IDE 转换基于Maven的Web应用程序支持Eclipse IDE 使用Maven模板创建项目 ...
结合 Maven 进行项目管理,可以构建出高效、模块化且易于维护的 Web 应用。 1. **Spring MVC 框架** - **概念**:Spring MVC 是 Spring 框架的一个模块,负责处理 HTTP 请求并呈现响应。它遵循 MVC 设计模式,将...
Maven作为一款流行的自动化构建工具,以其强大的依赖管理和项目构建功能而闻名;Eclipse则是广泛使用的开源IDE之一。本书《Maven Integration for Eclipse》由Tim O’Brien、Jason van Zyl等多位专家共同编写,旨在...
在进行持续集成时,Maven可以通过与CI服务器(如Jenkins、GitLab CI/CD)的集成,自动化地执行测试并报告结果。开发者也可以使用maven-site-plugin生成详细的测试报告,包括测试覆盖率、失败测试的堆栈跟踪等信息。 ...
一个自动化测试框架,可性能也可接口;maven负责项目管理,jenkins服务器就不需要安 装jmeter运行环境(错误的,maven项目配置pom文件),只需要注册脚本所需要的jar包 到本地仓库即可;git源码管理,maven构建; 1...
在IT行业中,持续集成和自动化构建是提升效率和质量的关键环节。Maven作为Java项目管理的重要工具,能够帮助我们统一构建、管理和部署项目。本文将详细介绍如何通过编写脚本实现Maven项目的版本号自动升级以及打包...
【持续集成与自动化测试】 持续集成(Continuous Integration, CI)是一种软件开发实践,它强调开发人员频繁地将他们的代码更改合并到主分支,通常每天至少一次。这一过程伴随着自动化构建和测试,以尽早发现和修复...
- **自动化构建**:Maven的自动化构建功能能够与持续集成服务器无缝集成,自动执行构建任务。 - **质量保证**:通过持续集成,可以在早期发现并修复缺陷,确保软件质量。 - **快速反馈**:持续集成提供了快速反馈...
Maven产品化支持是指将Maven用于企业级项目的构建和部署,以实现标准化、自动化和可重复性的过程。通过Maven,开发者可以轻松管理项目的生命周期,构建出符合生产环境需求的可执行包。 【描述】(由于给出的描述为...
这将帮助你亲手实践Maven的命令行操作,如`mvn clean`, `mvn compile`, `mvn install`等,体验Maven自动下载依赖、编译、测试和打包的过程。同时,你还可以学习到如何解决常见的构建问题,如依赖冲突、插件配置等。 ...
3. **测试**:使用Maven的Surefire插件进行单元测试,Failsafe插件进行集成测试。 4. **打包**:Maven可以将Web应用打包成WAR文件,这是Java EE服务器可部署的格式。 5. **部署**:配置Maven的`deploy`插件,将WAR...