In TDD, why OpenEJB and why Arquillian?

霸气de小男生 提交于 2019-11-30 07:25:46
Piotr Nowicki

There are two aspects in this case.

  1. Unit tests. These are intended to be very fast (execute the whole test suite in seconds). They test very small chunks of your code - i.e. one method. To achieve this kind of granularity, you need to mock the whole environment using i.e. Mockito. You're not interested in:
    • invoking EntityManager and putting entities into the database,
    • testing transactions,
    • making asynchronous invocations,
    • hitting the JMS Endpoint, etc.

You mock this whole environment and just test each method separately. Unit tests are fine-grained and blazingly fast. It's because you can execute them each time you make some important changes in code. If they were more complex and time-consuming, the developer wouldn't hit the 'test' button so often as he should.

  1. Integration tests. These are slower, as you want to test the integration between your modules. You want to test if they 'talk' to each other appropriately, i.e.:
    • are the transactions propagated in the way you expect it,
    • what happens if you invoke your business method with no transaction at all,
    • does the changes sent from your WebServices client, really hits your endpoint method and it adds the data to the database?
    • what if my JMS endpoint throw an ApplicationException - will it properly rollback all the changes?

As you see, integration tests are coarse-grained and as they're executed in the container (or basically: in production-like environment) they're much slower. These tests are normally not executed by the developer after each code change.

Of course, you can run the EJB Container in embedded mode, just as you can execute the JPA in Java SE. The point is that the artificial environment is giving you the basic services, but you'll end with tweaking it and still end with less flexibility than in the real container.

Arquillian gives you the ability to create the production environment on the container of your choice and just execute tests in this environment (using the datasources, JMS destinations, and a whole lot of other configurations you expect to see in production environment.)

Hope it helps.

I attended Devoxx this year and got a chance to answer the JBOSS dudes this question. Some of the test scenarios (the stuff i managed to scribble down):

  • Configuration of the container
  • Container integration
  • Transaction boundaries
  • Entity callback methods
  • Integration tests
  • Selenium recordings
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!