http://www.vogella.de/articles/JUnit/article.html
Developers write unit tests to check their own code.Unit testing differs from integration testing, which confirms that components work well together and acceptance testing, which confirms that an application does what the customer expects it to do. Unit tests are so named because they test a single unit of code.
Developers write unit tests to check their own code.Unit testing differs from integration testing, which confirms that components work well together and acceptance testing, which confirms that an application does what the customer expects it to do. Unit tests are so named because they test a single unit of code.
In the case of Java, a unit usually equates to a single class.
Testing is meant to improve the quality of your code, not decrease it.
Having said that, sometimes designing your system in a way that makes testing easier is still necessary. If you need to add a design element to support testing, ensure that it also increases the general quality of the system as a whole.
Say you have a class that can be instantiated only through a factory method . You may need to test an object of this class, but for some reason you can't call the factory. It may require resources passed as parameters that you don't have in your testing environment. Should you make the default constructor public just so your tests can instantiate the object and run the tests? No, of course not. That would reduce the quality of the system's design, allowing anyone to access a constructor that should be private. In this scenario, the tester needs to work harder to provide the needed resources and instantiate the object through the factory (perhaps through the use of MockObjects).
