Java – simulate / test core objects in my system

I was asked to change some classes that are core to the system we work on Each problematic class needs 5-10 different related objects, and these objects themselves need the same number of objects

The data is also extracted from several data sources. The project uses EJB2, so when testing, I don't have a container to introduce the dependencies I need!

I began to feel overwhelmed by the task I've tried using JUnit and easymock for unit testing, but as long as I simulate or stub one thing, I find that it needs more Everything seems to be tightly coupled so that I use my stub to reach about Level 3 or 4 to prevent nullpointerexceptions

Usually with this type of task, I only need to change and test But the shortest build cycle is about 10 minutes. I like very short iterative coding between execution (maybe because I'm not confident in my ability to write perfect code)

Does anyone know a good strategy / workflow to get out of this quagmire?

Solution

As you suggest, it sounds like your main problem is that the API you are using is too tightly coupled If you can modify the API, it is helpful to hide the direct dependencies behind the interface, so that you can cut off the dependency graph in the direct dependencies

If this is not possible, automatic simulation of containers may help This is basically a container that automatically indicates how to return a nested Abstract simulation with good default behavior When I was there Net framework, I don't recommend any Java

If you want to know about unit test patterns and best practices, I can only recommend xUnit test patterns

For the strategy of decoupling tightly coupled code, I suggest working effectively with legacy code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>