简体   繁体   English

我们刚刚开始使用持续集成和交付的遗留项目要使用哪种测试

[英]What kind of tests to use for legacy projects where we've just started using continuous integration and delivery

We have 12 legacy projects. 我们有12个旧项目。 One is an old Visual Basic application programmed 9 years ago, other are C# (.NET) aplications, 2 java projects, and os on. 一个是9年前编程的旧Visual Basic应用程序,另一个是C#(.NET)应用程序,2个Java项目以及os on。

We've just finished cleaning and creating a repository for each project (some of them were just folders sitting on different computers...). 我们刚刚完成清洁工作并为每个项目创建了一个存储库(其中一些只是位于不同计算机上的文件夹...)。

We have configured Jenkins with many useful plugins, bought two book: Continuous Integration and Continuous Delivery, not fully read yet. 我们为Jenkins配置了许多有用的插件,购买了两本书:持续集成和持续交付,尚未完全阅读。

We defined a deployment pipeline for our projects. 我们为项目定义了部署管道。 All are automatically being compiled after a commit to the repository and analysis of code is being done automatically (cyclomatic complexity, etc.). 在提交到存储库并自动完成代码分析(循环复杂性等)之后,所有文件都会自动进行编译。

However, we would like to know if there are tests (easy to add) that we can be using for our projects. 但是,我们想知道是否有可用于项目的测试(易于添加)。 We know about unit tests, however, writting unit tests for these projects would be too time consuming (if possible at all). 我们知道单元测试,但是,为这些项目编写单元测试会非常耗时(如果可能的话)。

Are there other kinds of tests we could add or other useful things we could be adding to our pipeline ? 我们是否可以添加其他类型的测试,或者是否可以在管道中添加其他有用的东西?

For some of the programs we are automatically generating an installer. 对于某些程序,我们会自动生成一个安装程序。

Also, at the end of the pipeline we have a manual step that moves the binary (installer) to a public folder on our apache server where people in the company can easily get the last stable binary (stable here being an application we manually install and test (exploratory test I think it's called) and if we don't see anything wrong, we promote it as a stable release). 此外,在管道的最后,我们有一个手动步骤,将二进制文件(安装程序)移动到我们的apache服务器上的公用文件夹中,公司中的人可以轻松获取最后一个稳定的二进制文件(这里稳定的是我们手动安装并测试(我认为这是探索性测试),如果我们没有发现任何错误,我们将其推荐为稳定版本。

Instead of writing unit tests for everything as it is right now, I believe you would be better off writing unit tests for new code you add. 我相信,与其为现在的所有内容编写单元测试,不如为添加的新代码编写单元测试更好。 You could assume that at the current state, everything works as expected; 您可以假设在当前状态下,一切都按预期进行。 then, when you find and fix a bug, or add a new feature, or pretty much make any change to the code base - write unit tests for that new code. 然后,当您发现并修复错误,添加新功能或几乎对代码库进行任何更改时,请为该新代码编写单元测试。

Regarding other kinds of tests, you may want to consider integration tests. 关于其他类型的测试,您可能需要考虑集成测试。 This answer to another SO question explains what integration tests are for and their value in comparison to unit tests. 另一个SO问题的答案解释了集成测试的用途以及与单元测试相比的价值。

I usually apply three levels of tests: 我通常会应用三个级别的测试:

  1. Unit tests - low-level tests that verify the correct behaviour of small, independent units of code. 单元测试-底层测试,用于验证小型独立代码单元的正确行为。 These tests are typically low-level, directly call other code/api's, run fast (during build time) and can break relatively fast too when doing extensive refactoring. 这些测试通常是低级的,可以直接调用其他代码/ api,运行速度快(在构建期间),并且在进行大量重构时也可能会相对快速地中断。
  2. Integration tests - medium-level tests that verify the correct behaviour of a number of units of code together. 集成测试-中级测试,它们一起验证多个代码单元的正确行为。 For example, an API provided by the backend to an external system or to the front-end. 例如,后端提供给外部系统或前端的API。 These tests are typically not too low-level, operate above code level (http requests, for example), run a bit less fast than unit tests (still during build time) but break less fast since they test against the boundaries of the system (REST endpoints, for example). 这些测试通常不是太低级,可以在代码级别以上运行(例如,http请求),运行速度比单元测试慢(仍然在构建期间),但是由于它们是针对系统边界进行测试的,因此中断速度较慢( REST端点)。
  3. End-to-end tests - high level tests that test the system as a whole. 端到端测试-用于测试整个系统的高级测试。 For a web application, typically browser testing is used (with Selenium, for example) where a browser is controlled by the tests, connecting to a running instance of the system. 对于Web应用程序,通常使用浏览器测试(例如,使用Selenium),其中浏览器由测试控制,并连接到正在运行的系统实例。 These tests are pretty high level (they simulate user behaviour), run slow and not during build time (since the system needs to be deployed first). 这些测试是相当高级的(它们模拟用户的行为),运行缓慢,而不是在构建期间运行(因为首先需要部署系统)。

In your case, I'd combine these types of tests. 在您的情况下,我将结合这些类型的测试。 Start by making an automated regression test suite using integration tests and/or end-to-end tests. 首先使用集成测试和/或端到端测试制作一个自动回归测试套件。 These types of test can hit a relatively large part of the system with not too much effort. 这些类型的测试可以在不花费太多精力的情况下对系统的较大部分进行测试。 When adding/changing functionality, first write one or more unit tests that verify the current state of the system. 添加/更改功能时,首先编写一个或多个单元测试,以验证系统的当前状态。 Then add/change test cases that verify the desired/new state of the system and change the system accordingly. 然后添加/更改测试用例以验证系统的期望/新状态,并相应地更改系统。

By the way: please reconsider the statement "writing unit tests for these projects would be too time consuming". 顺便说一句:请重新考虑以下语句:“为这些项目编写单元测试会非常耗时”。 Yes, it might be time consuming, but not writing tests at all would also be time consuming since you'd probably break functionality all the time without knowing, and find yourself needing to fix lots of issues. 是的,这可能很耗时,但是完全不编写测试也很耗时,因为您可能一直不知不觉地破坏功能,发现自己需要解决许多问题。

Hm, maybe a bit late a year afterwards ... but anyway, for people passing by here. 嗯,也许是一年后……但是无论如何,对于路过这里的人们来说。

Continuous delivery is the premium league of agile techniques. 持续交付是敏捷技术的高级联盟。 With a huge block of legacy code, you will probably not become "continuous" for quite some time. 有了大量的旧代码,您可能会在相当长的一段时间内不会变得“连续”。 Learn the ideas but don't get frustrated if you cannot reach them yet. 了解这些想法,但是如果您仍然无法理解它们,也不要感到沮丧。

Setting up repositories and pipelines still is a good idea. 设置存储库和管道仍然是一个好主意。 The repositories allow you to roll back defective changes quickly. 存储库使您可以快速回滚有缺陷的更改。 The pipelines give you the automation to run the large number of tests you will need to get on top of your code. 管道使您可以自动化运行大量测试,这些测试需要在代码之上进行。

You don't need any other tools or more plugins. 您不需要任何其他工具或更多插件。 Your programming languages most probably already have everything you need. 您的编程语言很可能已经拥有所需的一切。 What you need is know-how, conviction and patience. 您需要的是专业知识,信念和耐心。 Here is what worked for our teams: 这是我们团队的工作方式:

Get Michael Feather's Working Effectively with Legacy Code . 使Michael Feather的Legacy Code有效地工作 It gives you the techniques you need to start modifying the legacy code without fear of breaking it. 它为您提供了开始修改遗留代码所需的技术,而不必担心破坏它。 You think it's not possible to write unit tests for your legacy code? 您认为无法为旧代码编写单元测试吗? You're wrong about that. 你错了。 Feathers tells you how to do it. 羽毛告诉您如何做。 This is the know-how part. 这是专有技术部分。

Also, learn what characterization tests are and how they work. 另外,了解什么是表征测试以及它们如何工作。 You lost staff and thereby expert knowledge. 您失去了工作人员,从而失去了专业知识。 That code that nobody seems to know or remember what it does? 似乎没人知道或记得它的代码吗? Characterization tests help you probe it and enable you to refactor it. 表征测试可帮助您对其进行探查并使其重构。

Don't start a huge project to "make your code great again". 不要启动一个庞大的项目来“使您的代码再次变得出色”。 It took a while to write the code, it will take a while to fix it. 编写代码花了一段时间,而修复它也花了一段时间。 Get your code under test piece by piece. 逐步测试代码。 Whenever you develop a new feature, write tests for the feature plus the legacy code it immediately connects to. 每当您开发新功能时,都要为该功能及其立即连接的旧代码编写测试。 When you fix a bug, first write unit tests around the code you are fixing. 修复错误后,首先围绕要修复的代码编写单元测试。 This will increase your code coverage while still letting you get real work done. 这将增加代码覆盖率,同时仍然可以让您完成实际工作。 This is the patience part. 这是耐心的部分。

Every week, get a single resource (class, method, function) completely under test, ie with a statement and branch coverage of 100%. 每周,完全测试单个资源(类,方法,函数),即语句和分支覆盖率100%。 It's better to have 1 resource at 100% coverage than 10 resources at 10% coverage. 最好有1个资源在100%的覆盖率下比10个资源在10%的覆盖率下好。

Here's why: You can now refactor that resource. 原因如下:您现在可以重构该资源。 Read Robert C. Martin's Clean Code to get ideas how code can be made better. 阅读罗伯特·C·马丁(Robert C. Martin)的“ 干净代码”,以获取如何使代码变得更好的想法。 Then get some team members together and do a refactoring session: 然后将一些团队成员聚集在一起,进行一次重构会议:

Make a tiny improvement (rename a variable, remove a comment, extract a sub-method), then prove that all tests are still green, then pass the keyboard on to the next guy in the room. 进行微小的改进(重命名变量,删除注释,提取子方法),然后证明所有测试仍为绿色,然后将键盘传递给房间中的下一个家伙。 Repeat this over and over throughout the session. 在整个会话中重复上述步骤。 Don't forget to add sweets, chips, coke or beer to those sessions - make it a fun event. 不要忘记在这些课程中添加糖果,薯条,可乐或啤酒-这是一个有趣的活动。

Use the session to learn about the code, what it does, and why; 使用该会话来了解代码,代码的作用以及原因; this will enable all in the room to support that code that they wouldn't have touched otherwise. 这将使会议室中的所有人能够支持他们否则不会接触到的代码。

It also gives people an idea what they write all those unit tests for: to refactor code. 它还使人们知道他们为所有这些单元测试编写什么:重构代码。 Without they may perceive those unit tests as just some more useless burden. 没有他们,他们可能会认为那些单元测试只是更多无用的负担。 After all, it's sometimes the legacy developers, not the legacy code that need to be treated first. 毕竟,有时需要首先处理的是旧版开发人员,而不是旧版代码。 That's the conviction part. 那就是信念部分。

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

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