For some requests, I’m posting a very short squeeze of my previous article about setting up Continuous Integration, but "as a checklist for C #." At the same time added several alternatives to Travis.
Reading will take no more than 3 minutes, for whom it is interesting - I ask for cat.
Install the .NET Core SDK . Create a new repository and project.
dotnet new sln --name CIDemo dotnet new web --name web dotnet sln CIDemo.sln add web/web.csproj
Add the .travis.yml file to the project root folder.
language: csharp dotnet: 2.1.4 sudo: false env: global: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 script: - dotnet build CIDemo.sln -c Release
.travis.yml - Travis service file, contains environment settings, variables and commands. Documentation here
Login to Travis and give it access to your repository. Fill changes to the server.
Successful build:
And locally everything works for me Not a good build:
Add a test project
dotnet new xunit --name test dotnet add test/test.csproj package coverlet.msbuild -v 1.2.0 dotnet sln CIDemo.sln add test/test.csproj
xunit is a framework for testing, and coverlet.msbuild is a code coverage reporting tool.
Add a class and write a test for it.
`` c #
using System;
namespace web
{
public class IdProvider
{
public Guid NewId ()
{
return Guid.NewGuid ();
}
}
}
```c# using web; using Xunit; namespace test { public class IdProviderTest { [Fact] public void NewIdShouldReturnUniqueValues() { var idProvider = new IdProvider(); var id1 = idProvider.NewId(); var id2 = idProvider.NewId(); Assert.NotEqual(id1, id2); } } }
Add a command to the script section to run tests.
- dotnet test -c Release --no-build test/test.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
The minimum code coverage level is set using the / p flag: Threshold = TRESHOLD_LVL
Add a new section to .travis.yml
after_script: - bash <(curl -s https://codecov.io/bash)
The team sends test results to codecov. The documentation is here .
Log in to https://codecov.io and give it access to your repository.
The result of the codecov:
Everything, CI is configured.
language: csharp dotnet: 2.1.4 sudo: false env: global: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 script: - dotnet build CIDemo.sln -c Release - dotnet test -c Release --no-build test/test.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover after_script: - bash <(curl -s https://codecov.io/bash)
Instead of Codecov for work with tests it is possible to use https://coveralls.io/ . Also free for open source projects.
If you know other alternative and free solutions for CI - write, add to the article.
Thanks to all. I hope it turned out short and to the point.
Source: https://habr.com/ru/post/359042/
All Articles