4. Work in the constructor such as:
creating/initializing collaborators,
communicating with other services,
Logic to set up its own state removes seams
needed for testing, forcing subclasses/mocks
to inherit unwanted behavior. Too much work
in the constructor prevents instantiation or
altering collaborators in the test.
5. The LawOfDemeter specifies a style guideline:
"Only talk to your immediate friends."
Objects are passed in but never used directly
(only used to get access to other objects)
6. JUnit is a unit testing framework for the Java
programming language. JUnit has been
important in the development of test-driven
development.
7. import org.junit.*;
public class TestFoobar{
@Before public void setUp() throws Exception {}
@Test public void testSomething () {
//This piece will use asserts to verify.
}
@After public void tearDown() throws
Exception{}
}
8. Before: Hard to Test // An attempted test that
becomes pretty hard
/* Basic new operators called class HouseTest extends TestCase
directly in the class constructor. {
(Forever preventing a seam to
create different kitchen and public void testThisIsReallyHard() {
bedroom collaborators). */
House house = new House();
class House { /* I'm stuck with those Kitchen
Kitchen kitchen = new Kitchen(); and Bedroom objects created in
Bedroom bedroom; the constructor. */
House() { }
bedroom = new Bedroom(); }
}