简体   繁体   English

生产中的JUnit测试用例

[英]JUnit Test Cases on Production

We have recently started TDD and we are writing JUnit test-cases for each of the RESTful webservices that we develop. 我们最近开始了TDD,我们正在为我们开发的每个RESTful Web服务编写JUnit测试用例。 Is it a good idea to run the JUnit test-cases on the production environment when a new version is released? 发行新版本时,在生产环境上运行JUnit测试用例是一个好主意吗?

Background: Our web-app is enterprise web-app and has complex business logic. 背景:我们的网络应用是企业网络应用,具有复杂的业务逻辑。 The plan is to use @After and @AfterClass to cleanup the test-data generated by running test-cases. 计划是使用@After和@AfterClass清理通过运行测试用例生成的测试数据。

The web-app is available as both SaaS and on-premise editions and we are planning to validate upgrades for both edition if it's feasible and a good practice. 该Web应用程序既有SaaS版本也有本地版本,并且我们计划在可行和良好实践的情况下验证两个版本的升级。 I understand that we will be having this test-cases run on staging environment but to make sure that we have not broken anything during upgrade/deployment or environment has not created any diverse affect. 我知道我们将在临时环境上运行此测试用例,但要确保在升级/部署期间我们没有破坏任何东西,或者环境没有造成任何不同的影响。

Now question is, "Is it good practice? if no what is suggested?" 现在的问题是,“这是一种好的做法吗?是否没有建议?”

Your unit tests should just test the code. 您的单元测试应该只测试代码。 They shouldnt be modifying with external sources like databases and/or web services then they become integration tests. 他们不应该使用外部资源(例如数据库和/或Web服务)进行修改,然后它们将成为集成测试。

Generally I would suggest running unit tests before building/deploying your project to production, these can be run on a build server or QA / staging server. 通常,我建议在将项目构建/部署到生产之前运行单元测试,这些可以在构建服务器或QA /登台服务器上运行。 Only if they all pass do you deploy to production, then you know the build is stable in that sense. 只有所有这些都通过,您才可以部署到生产环境,然后您才能知道构建在这种意义上是稳定的。

If you have integration tests that do speak to other services and may modify data etc, I wouldnt run these on production. 如果您的集成测试确实可以与其他服务进行通信,并且可能会修改数据等,那么我就不会在生产环境中运行这些测试。 I would run them on your QA/Staging server against the code that is about to be released to production. 我将针对即将发布到生产环境中的代码在QA / Staging服务器上运行它们。

This is an interesting question; 这是个有趣的问题; I would say no you don't want to run a full unit test suite, however you might want to invest in maintaining a separate deployment smoke test suite. 我会说不,您不想运行完整的单元测试套件,但是您可能要投资维护一个单独的部署烟雾测试套件。

Reason - it's possible your test suites could affect a prod database, eg bug in an actual test fails to rollback or something. 原因-您的测试套件可能会影响产品数据库,例如,实际测试中的错误无法回滚或其他原因。

Also, you are not wanting to test your whole codebase in prod, just verify it deployed OK (assuming you got satsifactory results when you did run your whole test suite). 另外,您也不想在prod中测试整个代码库,只需验证它是否已部署好即可(假设您在运行整个测试套件时获得令人满意的结果)。

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

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