Unit Testing
Unit tests should be simple, readable, and behavior-driven. We want to achieve the following effect. Whenever a unit tests fails, the developer can directly tell what expected bahavior is not working from the test name. The developer can tell the test itself is correctly implemented at a glance.
Mockito
Car car = new Car(); car.manager = mock(Manager.class); when(manager.getServerPermission()).thenReturn(true); in startEngine() will call getServerPermission() car.startEngine(); veryfy(car.manager).getServerPermission(); car.setMiles(4); assert(4, car.getMiles());
JUnit
@Test(expected = IndexOutOfBoundsException.class)
public void empty() {
new ArrayList<Object>().get(0);
}