当前位置: 首页 > 编程日记 > 正文

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

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# 持续集成 单元测试

相关文章:

Handlebars模板引擎

介绍 Handlebars 是 JavaScript 一个语义模板库,通过对view和data的分离来快速构建Web模板。它采用"Logic-less template"(无逻辑模版)的思路,在加载时被预编译,而不是到了客户端执行到代码时再去编译&#…

字符集图标制作

字符集图标: 将网页上常见的icon做成font(字符集),以字体的方式插入到网页上,作用是减轻服务器负担,减少宽带。 我最常在这两个网站上下载字体图标: https://icomoon.io/app/#/select https://w…

Adobe源码泄漏?3行代码搞定,Flash动画无缝导入Android/iOS/cocos2dx(一)

[注] iOS代码已重构,效率提升90%,200层动画不卡。[2016.10.27] 项目介绍 项目名称:FlashAnimationToMobile 源码。 使用方法点这里。 这是一个把flash中的关键帧动画(不是序列帧)导出,然后在iOS/Android原生应用中解…

背景图像位置css_CSS背景图像大小教程–如何对整页背景图像进行编码

背景图像位置cssThis tutorial will show you a simple way to code a full page background image using CSS. And youll also learn how to make that image responsive to your users screen size.本教程将向您展示一种使用CSS编写整页背景图像的简单方法。 您还将学习如何使…

复习es6-解构赋值+字符串的扩展

1. 数组的解构赋值 从数组中获得变量的值,给对应的声明变量赋值,,有次序和对应位置赋值 解构赋值的时候右边必须可以遍历 解构赋值可以使用默认值 惰性求值,当赋值时候为undefined时候,默认是个函数就会执行函数 2.对象解构赋值 与…

Adobe源码泄漏?3行代码搞定,Flash动画无缝导入Android/iOS/cocos2dx(二)

[注] iOS代码已重构,效率提升90%,200层动画不卡。[2016.10.27] 上一篇 点此阅读 简要介绍了FlashToAnimation的功能,也就是将flash动画无缝导入到Android/iOS及cocos2dx中运行, 这一篇介绍这个库的使用方法。点此查看源码。 准备工作 首先…

the user operation is waiting for building workspace to complete解决办法

如果你在开发android应用程序中总是出现一个提示,显示“the user operation is waiting for "building workspace" to complete”,解决办法如下: 1.选择菜单栏的“Project”,然后把菜单栏中“Build Automatically”前面的对钩去掉。…

ios开发趋势_2020年将成为iOS应用开发的主要趋势

ios开发趋势Technology has always brought something new with time. And with these ever-changing technologies, you need to stay updated to get all the benefits from whats new. 随着时间的流逝,技术总是带来新的东西。 借助这些不断变化的技术&#xff0c…

http 权威指南 目录

第一部分 HTTP:Web的基础 第1章 HTTP概述 1.1 HTTP——因特网的多媒体信使 1.2 Web客户端和服务器 1.3 资源 1.3.1 媒体类型 1.3.2 URI 1.3.3 URL 1.3.4 URN 1.4 事务 1.4.1 方法 1.4.2 状态码 1.4.3 Web页面中可以包含多个对象 1.5 报文 1.6 连接 1.6.1 TCP/IP 1.6…

java初学者笔记总结day9

异常的概念throwable:异常,程序非正常执行的情况error:错误,程序非正常执行的情况,这种问题不能处理,或不应该处理exception:例外,程序非正常执行的情况,这种问题可以通过…

1小时学会:最简单的iOS直播推流(一)介绍

最简单的iOS 推流代码,视频捕获,软编码(faac,x264),硬编码(aac,h264),美颜,flv编码,rtmp协议,陆续更新代码解析,你想学的知识这里都有…

leetcode dfs_深度优先搜索:具有6个Leetcode示例的DFS图遍历指南

leetcode dfsHave you ever solved a real-life maze? The approach that most of us take while solving a maze is that we follow a path until we reach a dead end, and then backtrack and retrace our steps to find another possible path. 您是否解决了现实生活中的迷…

MySQL排序原理与MySQL5.6案例分析【转】

本文来自:http://www.cnblogs.com/cchust/p/5304594.html,其中对于自己觉得是重点的加了标记,方便自己查阅。更多详细的说明可以看沃趣科技的文章说明。 前言 排序是数据库中的一个基本功能,MySQL也不例外。用户通过Order by…

7.RabbitMQ RFC同步调用

RabbitMQ RFC同步调用是使用了两个异步调用完成的,生产者调用消费者的同时,自己也作为消费者等待某一队列的返回消息,消费者接受到生产者的消息同时,也作为消息发送者发送一消息给生产者。参考下图: 调用流程如下&…

1小时学会:最简单的iOS直播推流(二)代码架构概述

最简单的iOS 推流代码,视频捕获,软编码(faac,x264),硬编码(aac,h264),美颜,flv编码,rtmp协议,陆续更新代码解析,你想学的知识这里都有…

sh脚本每天创建一个文件夹_我每天创建一个月的视频。 这就是发生的事

sh脚本每天创建一个文件夹At the end of 2019 I promised that 2020 would be all about my YouTube channel. So thats what Ive been doing. 😃 在2019年底,我保证2020年将成为我的YouTube频道的全部 。 这就是我一直在做的。 😃 On the f…

1小时学会:最简单的iOS直播推流(三)使用系统接口捕获音视频数据

最简单的iOS 推流代码,视频捕获,软编码(faac,x264),硬编码(aac,h264),美颜,flv编码,rtmp协议,陆续更新代码解析,你想学的知识这里都有…

什么是bower

Bower是一个客户端技术的软件包管理器,它可用于搜索、安装和卸载如JavaScript、HTML、CSS之类的网络资源。其他一些建立在Bower基础之上的开发工具,如YeoMan和Grunt,这个会在以后的文章中介绍。 准备工作 安装node环境:node.js安装Git&#x…

ES6中export及export default的区别

在ES6中,export和export default均可用于导出常量、函数、文件、模块等,你可以在其他文件或模块中通过import (常量 | 函数 | 文件 | 模块)名的方式将其导入,以便能够对其进行使用,但在一个文件或模块中,export、impo…

sm2加密算法实例_实例说明加密算法

sm2加密算法实例Cryptography, at its most basic, is the science of using codes and ciphers to protect messages. 密码学从根本上讲就是使用代码和密码保护消息的科学。 Encryption is encoding messages with the intent of only allowing the intended recipient to un…

git---远程仓库版本回滚

开发中,发现有错误版本提交带远程分支master,怎么处理? 1 简介 最近在使用git时遇到了远程分支需要版本回滚的情况,于是做了一下研究,写下这篇博客。 2 问题 如果提交了一个错误的版本,怎么回退版本&#x…

1小时学会:最简单的iOS直播推流(四)如何使用GPUImage,如何美颜

最简单的iOS 推流代码,视频捕获,软编码(faac,x264),硬编码(aac,h264),美颜,flv编码,rtmp协议,陆续更新代码解析,你想学的知识这里都有…

团队任务四(无图)

任务要求: WBS练习对团队项目进行任务分解要求所有人共同参与队长列出需求成员进行估计队长领导大家达成共识形成团队报告,发至团队博客项目分解: 一、手机监控(24h) (1)手机当前运行程序监控(用以观察用户…

react测试组件_测试驱动的开发,功能和React组件

react测试组件This article is part of my studies on how to build sustainable and consistent software. In this post, we will talk about the thinking behind the testing driven development and how to apply this knowledge to simple functions, web accessibility,…

CDOJ 1073 线段树 单点更新+区间查询 水题

H - 秋实大哥与线段树Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Submit Status Practice UESTC 1073Appoint description: System Crawler (2016-04-24)Description “学习本无底,前进莫徬徨。” 秋实大哥对一旁玩手机的学…

1小时学会:最简单的iOS直播推流(五)yuv、pcm数据的介绍和获取

最简单的iOS 推流代码,视频捕获,软编码(faac,x264),硬编码(aac,h264),美颜,flv编码,rtmp协议,陆续更新代码解析,你想学的知识这里都有…

beta冲刺第一天

1、今天解决的进度 成员进度陈家权回复界面设计,由于成员变动加上和其他成员距离较远,服务器404赖晓连改进Alpha版本页面没能及时更新的问题雷晶获取提问问题时间更新到数据库林巧娜今天的任务是夜间模式功能块,没有完成,查找了很…

angular绑定数据_Angular中的数据绑定说明

angular绑定数据数据绑定 (Data Binding) 动机 (Motivation) Data often defines the look of an application. Interpreting that data into the user interface involves class logic (.component.html) and a template view (.component.ts) . Angular connects them throug…

WPF判断两个时间大小避免误差

进行查询操作的时候,经常用到判断开始时间和结束时间大小的条件,由于从控件上获取的时间除了年月日时分秒,还包括毫秒、微秒等,导致直接判断时间大小的时候会产生一些误差,如下: 结果分析:年月日…

1小时学会:最简单的iOS直播推流(六)h264、aac、flv介绍

最简单的iOS 推流代码,视频捕获,软编码(faac,x264),硬编码(aac,h264),美颜,flv编码,rtmp协议,陆续更新代码解析,你想学的知识这里都有…