Java EE环境中的单元测试 [英] Unit testing in Java EE environment

查看:123
本文介绍了Java EE环境中的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将我们的应用程序迁移到Java EE容器中,并寻找用于我们迁移的应用程序的单元测试(和集成测试)的工具。
我们的要求包括:

We're migrating our application into a Java EE container, and looking for tools to use for unit testing (and integration testing) our migrated app. Our requirements include:


  • 临时测试:按需手动运行测试的能力(由开发人员使用)开发代码时)

  • 批量测试:定期运行大量(且不断增长的)测试的能力

  • In-Container:集成测试在容器中部署EJB时使用EJB

  • 单元测试:不一定在EJB上下文中测试类

  • 很高兴:设置简单up,与ant / IDE集成

  • 无需测试Servlet / JSP - 只有POJO和EJB

  • Ad-hoc testing: the ability to run tests manually, on demand (to be used by developers while developing code)
  • Batch testing: the ability to run a large (and growing) set of tests regularly
  • In-Container: integration tests that use EJBs as they are deployed in the container
  • Unit testing: Testing of classes not necessarily inside an EJB context
  • Nice to have: Simple to set up, integrates with ant/IDE
  • No requirement to test Servlets/JSPs - only POJOs and EJBs

您在Java EE环境中使用什么来实现测试?您部署了哪些技术/设置?

What are you using to achieve testing in Java EE environment? What technologies/setup have you deployed?

我的研究发现了Cactus和JUnitEE:你有成功的设置吗?

My research have uncovered Cactus and JUnitEE: have you had success setting them up?

推荐答案

我们使用普通的JUnit进行单元测试和集成测试。我们使用VM参数在两者之间切换,并使用直接与服务器的标记进行注释。我们确实有一个自定义的TestSuite类,它根据这些信息查找并运行测试,因为它比手动维护要运行的测试更容易且更不容易出错。

We use normal JUnit for both unit tests and integration testing. We switch between the two using a VM argument, and have the tests annotated with markers for direct vs. server. We do have a custom TestSuite class though that finds and runs the tests based on this information, as it was easier and less error prone than manually maintaining which tests to run.

在我们的例子中,我们使用Spring远程处理来跟踪servlet和EJB(通过servlet),测试这两种情况只是Eclipse中的一个单独的启动配置。

In our case we use Spring remoting to talk to servlets and EJB's (via the servlets), and testing both cases is simply a separate launch configuration within Eclipse.

我们使用了JunitEE几年前,但最终放弃了它,赞成只使用JUnit。这使我们能够让开发人员在没有服务器的情况下完成所有测试,并在他们的IDE中运行这两个单元和我称之为低级集成测试。然后我们让构建机器针对现在部署在实际服务器中的相同代码运行相同的集成测试。这使得开发周期更快,因为我们很少需要运行服务器并部署服务代码。

We used JunitEE a few years ago, but eventually gave up on it in favor of just using JUnit throughout. This enabled us to have developers do all their testing without a server at all and run both unit and what I would call low level integration tests in their IDE. Then we let the build machine run the same integration tests against the same code now deployed in the actual server. This makes the development cycle much faster as we rarely need to run the server and deploy service code.

这篇关于Java EE环境中的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆