简体   繁体   English

春季,JUnit,休眠测试

[英]Spring, JUnit, Hibernate Testing

Can someone point me out to a good source of information on Spring mvc testing? 有人可以指出我关于Spring MVC测试的大量信息吗? 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 @Controllers:我希望能够模拟获取,发布或放置到特定路径,并通过模拟RequestBody使其到达@Controller

  3. Services: I would like to be able to call autowired services from JUnit tests and perform operations on entities. 服务:我希望能够从JUnit测试中调用自动装配的服务,并对实体执行操作。

In other words, I come from Rails and am trying to understand Spring way of testing, preferrably without Mocking anything... 换句话说,我来自Rails,试图了解Spring的测试方式,最好不要模拟任何东西。

You should read the Spring MVC Test project: https://github.com/spring-projects/spring-test-mvc 您应该阅读Spring MVC Test项目: https : //github.com/spring-projects/spring-test-mvc

Remember it is still in the attic. 请记住,它仍然在阁楼上。

Note from @ChristianMuller: 来自@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 实体:如果您对Spring / Hibernate / JUnit内存解决方案感兴趣,请查看以下内容: http : //tshikatshikaaa.blogspot.de/2012/09/junit-testing-spring-service-and-dao 。HTML

A great source is the spring framework documentation 一个很好的资源是spring框架文档

Entities: Usually in Spring Entities are simple POJOs, so in this case what you really want to do is test the Repositories. 实体:通常在Spring中,实体是简单的POJO,因此在这种情况下,您真正​​想做的就是测试存储库。

Services: Nothing special here, services can easily be tested either in the Spring context or using mocking to mock dependencies. 服务:这里没有什么特别的,可以在Spring上下文中或使用模拟来模拟依赖项来轻松测试服务。

Controllers: Since Spring 3.2, Spring MVC testing was added to the project. 控制器:从Spring 3.2开始,Spring MVC测试已添加到项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM