Posts tagged programming
Unit vs. Integration vs. Functional testing
Nov 6th
In a recent conversation with a colleague we discussed where the line was drawn between types of tests.
Unit tests
Unit tests usually won’t cross the boundaries of a class. There are definitely times when it’s acceptable, but generally speaking, you would almost always inject any dependencies as mock objects.
Integration tests
Integration tests will take one (or more classes) inside the same component/functionality and test those together. At this point, I have no problem crossing the file system boundary, but I would hesitate to go to a database or send messages to a broker (for example)
Functional tests
Puts a whole system to the test and usually will use most of it’s external dependencies (DB, JMS, …). A functional test will check that the system and data flow is ok.
For example
At work, we’ve grouped together to work on a complex Camel route that includes many processors, daos, file system operations, etc … I’ve tasked myself with writing the message writing component, specifically the component that receives messages and writes them to disk (Yes! I’m aware that Camel has this, but ours needs to be much more custom).
My message writer looks something like this:
I have 2 unit test clases:
- One for the factory class. In the unit tests, the factory builds mock MessageWriter instances.
- Another for the MessageWriter class. This class has a FileSystemWriter instance injected so that I can actually get full test coverage. Without its, my unit tests would have crossed the file system boundary. This injected dependency allows me to replace it in unit tests with a mock.
- FileSystemWriter isn’t unit tested … This is left up to the integration tests
As for integration tests, we use Spring. So in another suite of JUnit tests, I use the actual Spring context with test properties, and run the whole component. Obviously, assertions are much more complicated as I need to go to the file system and read file content to ensure all is good.
This very loosely coupled system gives the team members a tremendous amount of confidence, flexibility and autonomy while developing their own components; they need only a smart interface describing the component, and they can develop in complete isolation.
Arrays, what’s their point. Dito.
Dec 26th
When I first saw the post on Reddit, I found the reaction harsh (I still think the original poster meant “why use arrays instead of lists”).
As with Erlang, in Java arrays get in the way of readability. I understand arrays and the different usages, but I still prefer a List which is inifinitely more usable.

