Excellent presentation by Steve Freeman on sustainable TDD. Lots of great tips for making your unit tests easier to comprehend and maintain.
http://www.infoq.com/presentations/Sustainable-Test-Driven-Development
Excellent presentation by Steve Freeman on sustainable TDD. Lots of great tips for making your unit tests easier to comprehend and maintain.
http://www.infoq.com/presentations/Sustainable-Test-Driven-Development
Excellent blog on pair programming.
http://blog.xebia.com/2010/05/09/practical-styles-of-pair-programming/
A quote from the blog entry:
"No you're not faster on your own, you're just creating more crap for your colleagues to puzzle over and eventually delete. The code you write alone sucks. That guy that is getting on your nerves is trying to tell you (clumsily) that your code sucks, try to listen to him and you'll turn into a better programmer."
Have you encountered one or more of these styles? How many developers are pair programming these days?
sudo /Developer/Library/uninstall-devtools --mode=allorg.mockito.ArgumentCaptor<T>) in your unit tests. Argument captors are essential in verifying indirect outputs to your mocked collaborators.
public class Test{
@Captor ArgumentCaptor<Foobar> foobarCaptor;
@Before
public void init(){
MockitoAnnotations.init(this);
}
@Test
public void shouldDoSomethingUseful() {
//...
verify(mock.doStuff(foorbarCaptor.capture()));
Foobar capturedFoobar = foobarCaptor.getValue();
assertEquals("foobar", capturedFoobar.getName());
}
}
public class FooBarManagerTests {
@Mock private FooDependency mockFoo;
@Mock private BarDependency mockBar;
@InjectMocks private FooBarManager manager = new FooBarManagerImpl();
@Before
public void initMocks() {
// Initializes all mocks and then injects those mocks into the FooManager instance.
MockitoAnnotations.initMocks(this);
}
@Test
public void shouldDoSomething() {
manager.doSomething();
verify(mockFoo).doSomethingToFoo(any(String.class));
verify(mockBar).doSomethingToBar(any(Integer.class));
}
}