单元测试 之 Cactus

Cactus is a simple test framework for unit testing server-side java code (Servlets, EJBs, Tag Libs, Filters, ...).

The intent of Cactus is to lower the cost of writing tests for server-side code. It uses JUnit and extends it.

Cactus implements an in-container strategy, meaning that tests are executed inside the container.

The Cactus Ecosystem

The Cactus Ecosystem is made of several components:

  • The Cactus Framework: This is the heart of Cactus. It is the engine that provides the API to write Cactus tests.
  • The Cactus Integration Modules: They are front ends and frameworks that provide easy ways of using the Cactus Framework (Ant scripts, Eclipse plugin, Maven plugin, ...).
  • The Cactus Samples: They are simple projects that demonstrate how to write Cactus tests and how to use some of the Integration Modules.

    There are several kinds of unit testing frameworks. We categorize them in 3 types:

  • Type 1: code logic unit testing. Probably the best strategy for these tests is to use a Mock Objects type framework.
  • Type 2: integration unit testing. Cactus is typically in this category (we'll let you judge if it is the best or not :)). These tests will exercise the interactions with the container.
  • Type 3: functional unit testing. These unit tests will let you test the returned values from your server code. This is for example HttpUnit (Note that HttpUnit also performs standard functional testing - as opposed to functional unit testing -, which let you test full use cases - a login use case for example, which is comprised of several requests/responses).

Ideally you would use 3 different frameworks just to unit test your code ! Then you have to think about acceptance testing, system integration testing, ...

Cactus was developed to fit Type 2 but also to be a very good compromise for types 1 and 3, with the idea that it is much easier to have to write tests for a single framework than for several ! Moreover, you can never fully test your code. We believe Cactus provides a middle ground that provides a high confidence that your code will run when deployed. However, it is your choice and you can use Cactus only for type 2 if you wish.


转载于:https://www.cnblogs.com/menghe/articles/154057.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值