c# 持续集成 单元测试

Do you think continuous integration is not for you because you have no automated tests? Or no unit tests at all? Not true. Tests are important. But there are many more aspects to continuous integration than just testing. Let's see what they are.

您是否认为持续集成不适合您,因为您没有自动化测试? 还是根本没有单元测试? 不对。 测试很重要。 但是,持续集成有很多方面,而不仅仅是测试。 让我们看看它们是什么。

1.构建代码库 (1. Building the codebase)

This is the most critical issue continuous integration should solve. The main branch of your codebase should always build/compile. It seems silly to even mention it.

这是持续集成应解决的最关键问题。 您的代码库的主要分支应始终生成/编译。 甚至提到它似乎很愚蠢。

Take a team of 12. Say 1 faulty commit gets into the main branch. Everybody pulls. Here starts the process of finding out what's wrong and coordinating who should or will fix it. The confusion puts your whole team out of focus for around 30 minutes. Plus it causes frustration.

以12人为一组。假设1个错误的提交进入主分支。 大家拉。 从这里开始找出问题所在并协调谁应该或将要修复它的过程。 混乱会使整个团队失去焦点大约30分钟。 再加上它会导致沮丧。

Let's say this happens once a week (everybody makes mistakes eventually). 30 minutes x 12 people is 8 lost hours per week.

假设这种情况每周发生一次(每个人最终都会犯错误)。 30分钟x 12人每周损失8个小时。

If you are OK with that you might as well:

如果您还可以的话,也可以:

  • set up a CI process preventing faulty builds from getting into the main branch设置CI流程,以防止错误的构建进入主分支
  • give away a day off to one developer every week每周给一位开发人员放假

Same outcome, happier team :)

结果相同,团队更快乐:)

Setting up a CI process that ensures your codebase compiles is less than half a day's work. It's worth the effort.

设置确保您的代码库编译的CI流程不到半天的时间。 值得付出努力。

2.静态代码分析 (2. Static code analysis)

This comes for free in almost every language and is a one liner to run against a predefined set of rules:

几乎每种语言都免费提供此服务,并且可以按照预定义的规则运行:

  • Javascript: eslint, tslint

    Javascript: eslint , tslint

  • Java: sonarlint

    Java: sonarlint

  • Python: pylint

    Python: pylint

  • Go: golint

    围棋: golint

Setting up the static code analysis (or linting) takes 1 hour or so. So what are the benefits? You have well-formatted and "by the book" code in your main branch. That's a clear quality increase for your code base.

设置静态代码分析(或插入)需要1个小时左右。 那有什么好处呢? 您已经在主分支中设置了格式正确的代码,并且“按书”代码。 对于您的代码库而言,这显然是质量的提高。

If that is the least of your problems because your team is always rushing to meet deadlines, think of it this way. Your code review process will be faster. Anything that is in the area of code structure, best practices etc. is already checked by your CI process. No need to review or discuss it. Your developers can focus on the business content of code reviews.

如果那是您问题中最少的问题,因为您的团队总是急于按时完成任务,请以这种方式思考。 您的代码审核过程将更快。 CI程序已经检查了代码结构,最佳实践等方面的所有内容。 无需审查或讨论。 您的开发人员可以专注于代码审查的业务内容。

Great bonus: developers learn the code conventions automatically. The static analysis tool provides shows you the violated rule and explains why it is wrong to do that thing.

巨大的好处:开发人员可以自动学习代码约定。 静态分析工具向您显示违反的规则,并解释为什么这样做是错误的。

A hurdle with conventions is that developers are dogmatic about, for example, tabs versus spaces or those sorts of things. At the end of the day good conventions are those that are followed by all. Pick a set of standard conventions and roll with them.

约定的障碍是,开发人员对于例如制表符与空格或诸如此类的事情是教条主义的。 归根结底,良好的惯例是所有人遵循的惯例。 选择一组标准约定并将其滚动。

3.文化变革 (3. Culture change)

Continuous Integration is not a technical problem. It's a team process. You want to work in small increments and integrate code to the main branch often. See How to get started with CI for a larger discussion on what the culture goal actually is.

持续集成不是技术问题。 这是一个团队过程。 您希望以较小的增量工作,并经常将代码集成到主分支中。 有关文化目标实际上是什么的更多讨论,请参见如何开始使用CI 。

After the team masters the first critical elements, another shift should happen. People will realize that working in smaller increments is more efficient. Automated checks for basic mistakes will boost your confidence so you can merge code faster.

在团队掌握了第一批关键要素之后,应该再发生一次转变。 人们会意识到,以较小的增量进行工作会更有效率。 自动检查基本错误将增强您的信心,因此您可以更快地合并代码。

As a result, a branch's life span will decrease. Code review will be faster. Everybody will work with almost the latest code. It will prevent drifts and merge conflicts due to people working apart. See Why you should not use feature branches for a full list of benefits.

结果,分支的寿命将减少。 代码审查将更快。 每个人都将使用几乎最新的代码。 它可以防止由于人员分工而造成的漂移和合并冲突。 请参阅为什么不应该使用功能分支获取全部好处。

At the end of the day CI helps our pride and ego. Everybody should be happy to have a tool to catch their mistakes before they reach the world.

归根结底,CI有助于我们的骄傲和自我。 每个人都应该很高兴拥有一个能够在错误出现之前就发现错误的工具。

你是如何开始的? (How do you get started?)

Here is a very simple and actionable process to get started. It works regardless of your git provider: GitHub, Bitbucket, Gitlab, Azure DevOps, and all the others.

这是一个非常简单且可行的过程。 无论您的git提供程序如何,它都可以工作:GitHub,Bitbucket,Gitlab,Azure DevOps以及其他所有代码。

1.启用拉取请求(PR)流程 (1. Enable a Pull Request (PR) process)

Lock your main branch from direct pushes. Everything should come through PRs. Here are links on how to do this for Github, Bitbucket, GitLab, and Azure DevOps.

锁定主分支以免直接推动。 一切都应通过PR。 以下是有关如何为Github , Bitbucket , GitLab和Azure DevOps执行此操作的链接。

2.选择一个CI平台 (2. Pick a CI platform)

Every git provider allows you to define build pipelines for your PRs. The builds will run when the PR is created and for each new push to the branch the PR carries. A pre condition to complete your PR (= merge your branch) will be a successful build.

每个git提供程序都允许您为PR定义构建管道。 该构建将在创建PR时运行,并且对于PR进行的每次新的分支推送。 完成PR(=合并分支)的前提是构建成功。

The big CI players are CircleCI, Codeship, and Travis CI. I of course recommend Fire CI since its the platform I've built. But I don't claim it is better than the rest for each and every use case.

CI的主要参与者是CircleCI,Codeship和Travis CI。 我当然推荐Fire CI,因为它是我构建的平台。 但是我并没有说它在每个用例中都比其余的要好。

Just pick one and get started.

只需选择一个就可以开始。

3.定义2个班轮版本 (3. Define a 2 liner build)

The most basic build we want to achieve is build + static code analysis. Getting there is 2 or 3 commands in a shell.

我们要实现的最基本的构建是构建+静态代码分析。 在shell中到达那里有2或3个命令。

All CI platforms go for "configuration as code". You define your build in a *.yml file at the root of your repository and the platform picks it up.

所有CI平台都采用“代码配置”。 您在存储库根目录的* .yml文件中定义构建,然后平台将其选中。

With Fire CI, for example, you would need to add a .fire.yml file at the root of your repo that would look like this:

例如,使用Fire CI,您需要在仓库的根目录中添加一个.fire.yml文件,如下所示:

pipeline:   dockerfile: Dockerfile

Then you add a file named "Dockerfile" to build your app. Here are a few examples of simple Dockerfiles.

然后,添加一个名为“ Dockerfile”的文件以构建您的应用程序。 以下是一些简单Dockerfile的示例。

Any yarn/npm based tech like React/Angular/Vue/Node:

任何基于yarn / npm的技术,例如React / Angular / Vue / Node:

FROM python:3
WORKDIR /app
COPY . .
RUN yarn
RUN yarn lint
RUN yarn build

Python:

Python:

FROM python:3
WORKDIR /app
COPY . .
RUN pip install all_your_dependencies
RUN pylint all_your_python_files.py

Go:

走:

FROM golang:latest
WORKDIR /app
COPY . .
RUN go build -o main .

I could go on with many more. These examples are simplistic and could be improved with a few more commands. But you get the point: it's easy.

我可以继续下去。 这些示例非常简单,可以通过添加一些命令来进行改进。 但您明白了:这很容易。

可选:启用代码审查 (Optional: Enable code reviews)

Now that every code contribution comes through a PR, code reviews are easy to do. Every git provider has an awesome UI to present the differences and allow you to comment on code.

现在,每个代码贡献都来自PR,代码审查变得容易。 每个git提供程序都有一个很棒的UI来显示差异并允许您对代码进行注释。

If you are new to the process do not define a mandatory set of reviewers as it will slow your team down. Do start a best effort process to review each others' code. And build on that.

如果您不熟悉此流程,请不要定义一组必填的审阅者,因为这会使您的团队慢下来。 请尽最大努力来检查彼此的代码。 并以此为基础。

然后怎样呢? (What then?)

As with everything, think big but start small. Having a CI process in place opens a world of opportunities.

与所有事物一样,从大处着眼,从小处开始。 实施CI流程将打开机遇之门。

测试中 (Testing)

Once you have the basic process in place, it becomes a breeze to add your first automated test. And then some others. Low yet continuous effort can bring you awesome test coverage before you know it.

完成基本流程后,添加第一个自动化测试变得轻而易举。 还有一些。 不费吹灰之力和持续不断的努力可以为您带来无与伦比的测试覆盖率。

I recommend that you remain lean and not invest effort into writing tests. Check what breaks often or requires a lot of effort to test manually. Automate that. Always keep productivity in mind. Having a ton of tests just because is worth nothing.

我建议您保持精干,不要花精力编写测试。 检查哪些经常中断或需要大量的精力进行手动测试。 自动化。 始终牢记生产力。 仅仅因为一无所有而进行大量测试就一文不值。

其他津贴 (Other perks)

There are many tools out there that you can integrate to your CI process. They are not key but the effort versus benefits could be worthwhile.

您可以将许多工具集成到CI流程中。 它们不是关键,但是努力与收益是值得的。

A few examples are below. Links are for the GitHub marketplace but other git providers integrate as easily.

下面是一些示例。 链接是针对GitHub市场的,但是其他git提供程序也可以轻松集成。

  • Automatic update of dependencies: Depfu suggests dependencies to you to update automatically. This way you remain up to date doing small increments. This is always better than a once a year "let's bump everything" strategy.

    自动更新依赖关系: Depfu建议您自动更新依赖关系。 这样,您就可以以小幅增量保持最新状态。 这总是比每年一次的“让一切都变样”的策略更好。

  • Open source security: Snyk warns you about security threats in open source libraries.

    开源安全性: Snyk警告您有关开源库中的安全威胁。

  • Images optimisation: ImgBot detects large images in your repository and submits a PR with size optimized version. Relevant for front end projects, but still nice.

    图像优化: ImgBot在您的存储库中检测到大图像,并提交具有尺寸优化版本的PR。 与前端项目有关,但仍然不错。

There are many more out there. Browse the marketplace for things that could solve a problem for you.

还有更多。 浏览市场,寻找可以为您解决问题的事物。

Careful though! Resist the urge to use everything that comes to mind. Pick the ones that really provide a productivity boost. Free metrics or tools that you don't consider carefully are harmful as people are not sure what to do with them.

小心点! 抵制使用想到的一切的冲动。 选择那些真正可以提高生产力的产品。 您不会仔细考虑的免费指标或工具有害无益,因为人们不确定该如何处理。

结论 (Conclusion)

You do not need fancy tests suites to get started with Continuous Integration.

您不需要高级测试套件即可开始进行持续集成。

Literally 2 hours of effort can get you rolling. And it'll enable a virtuous circle for your team's productivity.

从字面上看,2个小时的工作可以让您滚动。 这将为您的团队的生产力带来一个良性循环。

The bigger your team and your projects, the greater the benefits. In 2020 there is no good reason to not have a CI process.

您的团队和项目越大,收益越大。 在2020年,没有充分的理由不进行CI程序。

Feel free to contact me if you need help setting up a CI process for your team. I'll be happy to help if I can.

如果需要帮助为您的团队设置CI流程,请随时与我联系 。 如果可以的话,我很乐意提供帮助。

Thanks for reading and good luck!Originally published on The Fire CI Blog.

感谢您的阅读和好运! 最初发布在Fire CI博客上。

翻译自: https://www.freecodecamp.org/news/continuous-integration-without-unit-tests/

c# 持续集成 单元测试

c# 持续集成 单元测试_如何在不进行单元测试的情况下设置持续集成相关推荐

  1. java 单元测试_在springboot中写单元测试解决依赖注入和执行后事务回滚问题

    往期文章 「Java并发编程」谈谈Java中的内存模型JMM 面试官:说说你知道多少种线程池拒绝策略 为什么不要在MySQL中使用UTF-8编码方式 前言 很多公司都有写单元测试的硬性要求,在提交代码 ...

  2. api自动化_如何在不增加人员的情况下自动化API安全程序

    api自动化 在这篇文章中,我们将撰写一篇综合文章,内容涉及如何在不增加人员的情况下自动执行API安全程序. 在现代世界中,数据对于提供者和消费者都至关重要. 数据科学的出现证明了这一事实. 对于某些 ...

  3. 静态创意和动态创意_创意只有在有限制的情况下才令人印象深刻

    静态创意和动态创意 重点 (Top highlight) You've probably heard the phrase before. It's a principle which origina ...

  4. SpringBootTest单元测试—加入@Test无法启动测试方法,什么情况下需要加@RunWith(SpringRunner.class)?

    spring环境下单元测试: SpringBoot环境下单元测试: 一.SpringBoot2.4.0之后 二.2.2.0 < SpringBoot < 2.4. 三.SpringBoot ...

  5. pc分布使用率情况_如何在不违反法律的情况下获得廉价和免费的PC游戏

    pc分布使用率情况 Being a PC gamer can be an expensive business. You spend hundreds on your hardware and the ...

  6. kde重启_我可以在不注销的情况下重新启动KDE Plasma桌面吗?

    问题描述 我只是谈论标准的KDE桌面.运行任务栏一段时间后(多天)停止正常工作.这是由于某种未确诊的错误,但目前这确实不是我的麻烦.只要我注销并重新登录,它就会被修复. 我必须关闭一切,虚拟机等持续进 ...

  7. php带参数单元测试_一文搞定单元测试核心概念

    基础概念 单元测试(unittesting),是指对软件中的最小可测试单元进行检查和验证,这里的最小可测试单元通常是指函数或者类.单元测试是即所谓的白盒测试,一般由开发人员负责测试,因为开发人员知道被 ...

  8. python做单元测试_如何使用python做单元测试?

    很多编程小白不太理解单元测试,为什么要进行单元测试呢?很简单,主要是提高代码的正确,同时确保重构不出错.接下来我们一起学习怎么用python做单元测试吧. python内置了一个unittest,但是 ...

  9. 浏览器崩溃_如何在浏览器不崩溃的情况下过滤200万行数据?

    作者|Bruno Couriol 编辑|无明 最近我分配到了一个非常有趣的任务:在前端显示 1GB 文件和 200 万行数据,并实现过滤,在这篇文章中,我将分享我是如何完成这个任务的. 背景 我曾经创 ...

最新文章

  1. python数据清理的实践总结_python 数据的清理行为实例详解
  2. 上下定高 中间自适应_移动端布局上下固定中间自适应
  3. 【Jmeter】压力测试工具 Jmeter 使用
  4. comparing ORB and AKAZE
  5. linux lib目录找不到,linux中jpeglib库文件我安装了,但是我运行自己写的代码总是找不到这个库...
  6. 物联网建设中通讯互联层的终极解决方案
  7. Unix 风雨五十年:老兵远去,新秀崛起!
  8. shp格式详解(一)
  9. 组合导航GPS+IMU
  10. linux 极点五笔,Linux 安装ibus极点五笔输入法备忘录
  11. 修改windows软件图标
  12. 简单的动画(梦幻西游)
  13. Apache JMeter 5.1.1 Win 10 环境变量配置
  14. 技嘉b365m小雕驱动工具_【黑苹果】技嘉B365M小雕+i5 9400F+RX590EFI分享
  15. mysql 取差值_MySQL计算相邻两行某列差值的方法
  16. 2020 Stibo Systems全球事业部新财年启动大会胜利召开
  17. Maven打包常见问题
  18. 类变量、成员变量、实例变量、局部变量、静态变量、全局变量 的解释。
  19. cmd无法加载命令解决方法
  20. 浅谈代码规范基础调试几道面试题

热门文章

  1. 【java】巨菜博主安装jdk为什么每次都失败?
  2. java 文件下载 【学习记录】
  3. 数据结构课程上机参考代码
  4. 行内标签(最常用的:a标签、img标签、span标签)
  5. HTML5:理解head
  6. 化敌为友 运营商组团拥抱OTT为哪般
  7. 模态框获取id一直不变,都是同一个id值
  8. 1.3 使用jmeter进行http接口测试
  9. PHP中session_register函数详解用法
  10. ComponentName(String pkg, String cls)