Billy Sclater wrote:
The article and original statement seem contradictory. How can I have 100% coverage, if I am NEVER supposed to use the resources in the list (files etc..)? For example, how can I test a file copier class, if I am never supposed to use files in a unit test?
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:A Unit test will never use real other classes. All dependencies are mocked. If a unit test uses other classes, it's not a unit test, it's an integration test
Tim Driven Development | Test until the fear goes away
Tim Driven Development | Test until the fear goes away
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Tim Cooke wrote:
I think the definition of a Unit is a bit more flexible than that. I see it as a logical unit within your application which may consist of a single class or multiple classes. For example, the product I develop at work has to publish messages on a Tibco bus. So I have a "unit" that takes a message in the format of our domain model and translates that into a Tibco format to be sent down the wire. My Unit Tests here will be to ensure that if I put in domain object A then I get out Tibco message B. As it happens there are a handful of classes and things in the middle that actually make that happen but I do not necessarily have any unit tests for those individually. My "unit" in this case is the code that translates the message from format A to format B. I don't really care at this point how many classes are involved.
The purpose of having unit tests in your code is to give you the ability to refactor safely. In my example above, I am now free to completely change how I implement building those messages but as long as my tests pass then I know I'm building those messages correctly. If I had unit tests around each individual class in there with Mocks for every interaction with other classes then I would be encasing my code in concrete. I'm now writing tests to specify the implementation. I don't want that. I want tests to specify the functionality.
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:I believe you are thinking of an integration test.
Tim Driven Development | Test until the fear goes away
Don't get me started about those stupid light bulbs. |