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 private SimpleDAO dao;

Ready to Test !

Advertisements
Tagged with: , ,
Posted in JUnit, Spring, Testing
One comment on “Testing with SpringJUnit4ClassRunner
  1. […] If using SpringJUnit4ClassRunner methods demarcated with @Transactional will not commit unless @Rollback(false) or […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: