-
Notifications
You must be signed in to change notification settings - Fork 3
Automated Testing
Tim Tong edited this page Aug 2, 2015
·
12 revisions
- JUnit
- Mockito
- PowerMockito
*** Should only be using mock objects and mocked behavior for unit testing.
The most typical JUnit commands will be:
- Assert.assertEquals(Object expected, Object actual);
- Assert.assertTrue(boolean expression);
- Assert.assertFalse(boolean expression);
- Assert.assertNull(Object object);
- Assert.assertNotNull(Object object);
See JUnit API for more.
To create a test:
public class SomeTestClass {
@Test
public void test() {
}
}
To create a mock object:
@RunWith(MockitoJUnitRunner.class)
public class SomeTestClass {
@Mock
private Object object;
}
To inject a mock object into an autowired member variable:
@RunWith(MockitoJUnitRunner.class)
public class SomeTestclass {
@Mock
private Object object;
@InjectMocks
private ClassToBeInjected myObject;
}
To mock behavior:
@Test
public void test() {
Mockito.when(object.method(parameters)).thenReturn(returnObjectOrValue);
}
Integration testing is temporarily put on hold.