On Github nllarson / testing-presentation
By Nick Larson
We needed people to run the tests!
Wikipedia: A method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine if they are fit for use.
Nick Larson: Testing a single class, method, piece of code (Unit). Without any real dependencies.
http://code.google.com/p/mockito/
Mockito offers a simple and intuitive approach: you ask questions about interactions after execution. Using mockito, you can verify what you want.
when(foo.bar(0)).thenReturn(99);
when(foo.bar(0)).thenReturn(99).thenReturn(77);
when(foo.bar(0)).thenThrow(new Exception());
when(foo.bar(anyInteger())).thenReturn(99);
when(foo.baz(any(User.class))).thenReturn(99);
verify(foo, times(3)).bat(anyString());
verify(foo, atLeastOnce()).bat(anyString());
verify(foo, atMost(3)).bat(anyString());
when(foo.loadUser(anyString())).thenAnswer(new Answer() { public User answer(InvocationOnMock invocation) throws Throwable { User user = null; String userId; userId = (String) invocation.getArguments()[0]; if (!userId.equals("abc123")) { user = new User(); user.setId(userId); user.setName("Test User"); } return user; } });This allows some logic to be thrown into the stubs. In this example we are wanting to only 'load' a user if the id is NOT == 'abc123'.
Wikipedia: Individual software modules are combined and tested as a group. It occurs after unit testing. Integration testing takes as its input modules that have been unit tested, groups them in larger aggregates
Nick Larson: Yeah, what they said! ^^^^^^