Blog Archives

Integration Testing with DB Unit

First checkout DB Unit: DbUnit is a JUnit extension targeted at database-driven projects that, among other things, puts your database into a known state between test runs. … DbUnit has the ability to export and import your database data

Tagged with: , , ,
Posted in Database, JUnit, Testing

Testing with SpringJUnit4ClassRunner

Testing with SpringJUnit4ClassRunner is breeze. First add annotations: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { “/appContext.xml” }) public class SimpleDaoTest{ … } Place resources on classpath: src/main/test/resources Add dependencies: <dependency>     <groupId>org.springframework</groupId>     <artifactId>spring-test</artifactId>     <version>${springframework.version}</version>     <scope>test</scope> </dependency> Annotate test class: @Autowired

Tagged with: , ,
Posted in JUnit, Spring, Testing

Unit Testing

Mockito is a mocking Framework <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>${mockito.version}</version> <scope>test</scope> </dependency> It allows us to easily mock objects: mock(MyService.class) //using mock static method or @Mock +  MockitoAnnotations.initMocks(this); We can specify the desired behavior of the mocks using Mockito’s fluent APIs:

Tagged with: , ,
Posted in JUnit, Mockito, Testing