0

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...

2

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

At the spring-test-mvc project they also point you to github.com/spring-projects/spring-mvc-showcase which is an even better package. Awesome, thanks!
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.