wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Object-Oriented Thought, dependency injection, and software testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Object-Oriented Thought, dependency injection, and software testing" Watch "Object-Oriented Thought, dependency injection, and software testing" New topic
Author

Object-Oriented Thought, dependency injection, and software testing

Thad Humphries
Greenhorn

Joined: Feb 04, 2011
Posts: 14

When I got my MS twenty years ago, object-oriented was all the rage and UML was still a ways off. Software testing was in its infancy and no one (AFAIK) had even thought of dependency injection. Can you give any insight on software testing and object-oriented thought? For example, something I puzzle over is the balance encapsulation via private members and methods with the need to access these methods from JUnit tests.


"Hell hath no limits, nor is circumscrib'd In one self-place; but where we are is hell, And where hell is, there must we ever be" --Christopher Marlowe, Doctor Faustus (v, 121-24)
Matt Weisfeld
author
Greenhorn

Joined: May 01, 2013
Posts: 24
    
    5
Hi Thad,

There is a lot of discussion on abstract and concrete classes and how you can dynamically load classes, but not as it pertains directly to dependency injections. I do go through a lot on the process of developing and testing applications, but not with any specific approach.

Thanks,

Matt

Matt Weisfeld
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4397
    
    8

My take on it is that if you need to access private members and methods to run your unit tests, you're usually doing it wrong. Tests should be based on the public interface of components. Otherwise you're tying your tests too closely to your implementation, making change and refactoring far more painful than they should be.
Matt Weisfeld
author
Greenhorn

Joined: May 01, 2013
Posts: 24
    
    5
This is one of the most interesting debates regarding OO. From the beginning the premise was that all data possible should be private. In fact, perhaps all data should be private and only accessible via accessor methods (or properties).

I totally agree that you shouldn't change anything for testing purposes. It's kind of like the uncertainty principle. How can you test things if you have to change them to test them!
 
GeeCON Prague 2014
 
subject: Object-Oriented Thought, dependency injection, and software testing