简体   繁体   English

在Eclipse中运行需要Maven预集成测试执行的JUnit集成测试?

[英]Running JUnit integration tests in Eclipse that need Maven pre-integration-test executions?

I have writting some JUnit integration tests that currently run from Maven (via the command line or out CI server). 我编写了一些当前从Maven(通过命令行或CI服务器)运行的JUnit集成测试。 These integration tests automatically configure and startup the database and servlet container inside of Maven's 'pre-integration-test' lifecycle phase. 这些集成测试会在Maven的“集成前测试”生命周期阶段自动配置并启动数据库和servlet容器。

I would very much like to run these JUnit tests (like I do all our other tests) from within an Eclipse JUnit launch configuration. 我非常想从Eclipse JUnit启动配置中运行这些JUnit测试(就像我进行所有其他测试一样)。 However, the JUnit launch configuration does not trigger the pre-integration-test executions and thus the environment to test is not properly established. 但是,JUnit启动配置不会触发集成前测试执行,因此无法正确建立要测试的环境。

Whats the best way to get this to work? 使此工作最佳的方法是什么?

You can setup Maven Run Configurations to run within Eclipse, using Run -> Run Configurations , assuming you have the Maven plugin for Eclipse. 您可以使用Run -> Run Configurations Run Configurations将Maven Run Configurations设置为在Eclipse中Run -> Run Configurations ,并假设您具有Eclipse的Maven插件。 Using the goals clean verify will run unit tests and integration tests. 使用目标进行clean verify将运行单元测试和集成测试。

Also if you use the failsafe reports Maven plugin, you can create JUnit style reports, that you can open in Eclipse using the JUnit framework, to see which tests passed and failed. 同样,如果使用故障安全报告Maven插件,则可以创建JUnit样式报告,可以使用JUnit框架在Eclipse中打开该报告,以查看通过和失败的测试。

One way to do this I just discovered is to use Eclipse Launch Groups as shown here: 我刚刚发现的一种方法是使用Eclipse启动组,如下所示:

http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.cdt.debug.application.doc%2Freference%2Fcdt_u_run_dbg_launch_group.htm http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.cdt.debug.application.doc%2Freference%2Fcdt_u_run_dbg_launch_group.htm

I missed this because this capability, while language independent needs to be installed from the C/C++ side of Eclipse as shown here: 我错过了这一点,是因为需要从Eclipse的C / C ++端安装与语言无关的功能,如下所示:

What installable component provides 'launch groups' in Eclipse? 哪些可安装组件在Eclipse中提供“启动组”?

Within the launch group the first job should run a maven task to process test resources, the next jobs launch the server(s), and then finally a job to execute the junit tests. 在启动组中,第一个作业应运行一个maven任务来处理测试资源,接下来的作业将启动服务器,然后最后一个作业来执行junit测试。

I don't know what database you want to use, but for unit tests its handy to use an in memory database and maybe also an embedded servlet container. 我不知道要使用哪个数据库,但是对于单元测试而言,使用内存数据库以及嵌入式servlet容器非常方便。 Maybe you could use something like http://arquillian.org/ 也许您可以使用http://arquillian.org/之类的东西

JUnit framework should be mainly used for Unit testing and not Integration testing. JUnit框架应主要用于单元测试,而不是集成测试。 Integration testing could be performed by QA team. 质量检查团队可以执行集成测试。

If you have lot of Integration plumbing code then you should considering Mocking of external elements, such as Databases and web services calls. 如果您有大量的集成管道代码,则应该考虑外部元素的模拟,例如数据库和Web服务调用。

Concentrate mainly on testing code that you have written.Add negative, positive and exceptional test scenarios. 主要专注于您编写的测试代码。添加否定,肯定和例外的测试方案。 That will give your code more credibility than full integration test. 这将使您的代码比完整的集成测试更有信誉。

For Database I suggest using DBUNIT > http://www.dbunit.org/ which is an excellent tool for testing database plumbing. 对于数据库,我建议使用DBUNIT> http://www.dbunit.org/ ,它是测试数据库管道的出色工具。 This tool can create XML schema from your database and you can keep data as xml replicating the database. 该工具可以从您的数据库创建XML模式,并且可以将数据保留为xml复制数据库。 This will avoid changing any dataset for your JUnit testing. 这将避免为您的JUnit测试更改任何数据集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在集成前测试期间运行maven-clean-plugin而不清理默认目标目录 - Running maven-clean-plugin during pre-integration-test without cleaning default target directory Jetty不在集成前测试阶段(Maven)开始 - Jetty doesn't start in pre-integration-test phase (Maven) 更改Maven故障安全预集成测试的工作目录以查找Spring配置 - Change working directory for Maven failsafe pre-integration-test to find Spring configuration 无法在预集成测试阶段启动Jetty - Not able to start Jetty in pre-integration-test phase 是否有类似于Integration-Test的集成前和集成后测试的类名称约定 - Is there any class name conventions for pre-integration-test and post-integration-test similar to integration-test 在来自Maven的eclipse-test-plugins上运行JUnit测试 - Running JUnit tests on eclipse-test-plugins from maven maven没有运行集成测试方法 - maven not running integration test methods Junit 5 集成测试在 maven 3.5.2 构建中失败 - Junit 5 integration test failed in maven 3.5.2 build Eclipse执行集成测试,但Maven不执行 - Eclipse executes integration tests, but Maven does not 如何在运行 junit4 集成测试之前通过 maven 部署战争? - How to deploy a war via maven before running junit4 integration tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM