We employ both Spring and Hibernate to implement business and data access layers in our current project. Our aim is to bring clear separation between those two layers. Beans in business layer act as service entry points. They simply realize our use case scenarios. They are also good candidates as start and end points for business transactions and authorization level security checks to allow or deny users who attempt to execute the business logic.
Testability is our main concern as well, and actually I want to bring the discussion to that specific point. We have clearly separated layers, and each of those layers should be tested in isolation. Unit testing using mock objects or using Cactus to run tests in container appear as two distinct alternatives at first glance. For example, business logic in our service layer objects are tested simply mocking data access layer objects. But things get a little bit complicated, when it comes to test those required behavior while security and transactional contexts are available. We need to provide an environment in which those two middleware services should be up and running or provide the test base with their mock implementations at least. This is obviously a difficult task and things could get more complicated if our system depends more and more on such components.
Assume that we provided our system with those required services or their mock implementations, but we could never be sure that our system act as if, it were in real production environment. Another point with this kind of unit testing is that our tests could be so fine grained that we never see any interactions between objects in different layers. Each object is tested in isolation from other dependent objects. For example, when we test service objects in business layer, we only check business logic in them. We do not hit real data access objects and database either. This may not seem to be a problem, but anyway we cannot be hundred percent sure that our system will work as complete in the target environment.
I think, Cactus in-container testing framework relieves us from problems/difficulties mentioned in above paragraphs. I actually do not see using Cactus to do in container testing and testing with mock objects as opponents, but complementary to each other. Cactus tests appear more as integration unit tests, while mock objects are used mainly in testing business logic in isolation.