marcelorocks
marcelorocks

Reputation: 2035

Spring, JUnit, Hibernate Testing

Can someone point me out to a good source of information on Spring mvc testing? I would like to test:

  1. Entities: I want to be able to create a new record in the database, fetch all records and assert on the new elements count.

  2. @Controllers: I would like to be able to simulate a get, post or put to a specific path and get it reach the @Controller by simulating RequestBody

  3. Services: I would like to be able to call autowired services from JUnit tests and perform operations on entities.

In other words, I come from Rails and am trying to understand Spring way of testing, preferrably without Mocking anything...

Upvotes: 0

Views: 467

Answers (2)

Alexander Jardim
Alexander Jardim

Reputation: 2476

You should read the Spring MVC Test project: https://github.com/spring-projects/spring-test-mvc

Remember it is still in the attic.

Note from @ChristianMuller:

  1. Entities: In case you are interested in an Spring/Hibernate/JUnit In-Memory solution, have a look at this: http://tshikatshikaaa.blogspot.de/2012/09/junit-testing-spring-service-and-dao.‌​html

Upvotes: 1

geoand
geoand

Reputation: 64079

A great source is the spring framework documentation

Entities: Usually in Spring Entities are simple POJOs, so in this case what you really want to do is test the Repositories.

Services: Nothing special here, services can easily be tested either in the Spring context or using mocking to mock dependencies.

Controllers: Since Spring 3.2, Spring MVC testing was added to the project.

Upvotes: 0

Related Questions