简体   繁体   English

与JUnit和Web MVC的集成测试

[英]Integration tests with JUnit and web MVC

I am working on a Spring MVC application. 我正在开发Spring MVC应用程序。

Unit tests are already writen (nice 85% code coverage and lots of assertions :) 单元测试已经写好(85%的代码覆盖率和很多断言:)

Now I need to write integration tests. 现在,我需要编写集成测试。 I already have a look at stackoverflow still I do have some questions 我已经看过stackoverflow了,但我确实有一些疑问

  • Right now I am using a standard maven structure with main and test directories, do you recommend to create another directory called integration-tests and write the unit tests there? 现在,我正在使用带有主目录和测试目录的标准Maven结构,您是否建议创建另一个名为Integration-tests的目录并在其中编写单元测试? If so, why? 如果是这样,为什么?
  • Another alternative would be to write the integration tests in the "tests" directory, mixing unit and integration tests, and then using maven to run one or the other (maybe using different file suffixes depending on the test type) 另一种选择是在“测试”目录中编写集成测试,混合单元测试和集成测试,然后使用maven运行一个或另一个(可能根据测试类型使用不同的文件后缀)
  • In any case, the way I am planning to run the integration tests is essentially to (almost) reuse the unit tests of the controllers WITHOUT injecting mocks, that means that my current stack (Controller-Service-DAO) will contain no mocks (of course, in the unit tests, it does), by removing the mocks I will access to the real resources (Database and so), is this a good approach? 无论如何,我计划运行集成测试的方式实质上是(几乎)重用控制器的单元测试,而无需注入模拟,这意味着我当前的堆栈(Controller-Service-DAO)将不包含模拟(当然,在单元测试中确实如此),通过删除模拟程序,我将访问实际资源(数据库等),这是一种好方法吗?

UPDATE: Just to clarify, the project has not JSP or any HTML-related views, output is XML which can be easily validated with XSDs 更新:只是为了澄清,该项目没有JSP或任何与HTML相关的视图,输出的是XML,可以使用XSD轻松验证

I am assuming that you have used JUNIT to create your unit tests to achieve the impressive 85% code coverage. 我假设您已经使用JUNIT创建了单元测试,以实现令人印象深刻的85%的代码覆盖率。 Please notice that JUNIT is designed for unit testing only (thus the name JUNIT). 请注意,JUNIT仅用于单元测试(因此名称为JUNIT)。 Unit testing is done while the code is running in the development environment. 当代码在开发环境中运行时,将完成单元测试。

Integration testing can only be performed once the target code has been deployed in the target integration environment. 只有在目标集成环境中部署了目标代码后,才能执行集成测试。

You have mentioned that you application isn't a web application. 您已经提到您的应用程序不是Web应用程序。 Is it SOAP/Rest Web Service? 是SOAP / Rest Web服务吗? If so, you can use Soap UI [http://www.soapui.org/], to create and save automated regression/integration tests. 如果是这样,您可以使用Soap UI [http://www.soapui.org/]创建并保存自动回归/集成测试。

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

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