使用门户部署Azure Web应用程序时自动进行单元测试

时间:2022-05-21 19:20:46

I have an ASP.NET MVC solution with the following structure:

我有一个ASP。NET MVC解决方案的结构如下:

Solution.sln
--- Solution/Main.csproj
--- Solution.Services.UnitTest/Solution.Services.UnitTest.csproj

For simplicity in this question, lets say my Main solution is both my website and services. So we have one solution with is the "application".

为了简单起见,让我们说我的主要解决方案是我的网站和服务。我们有一个解决方案就是“应用”。

The UnitTest solution is a simple solution that refers the Main project, but with a lot of unit tests (using NUnit).

UnitTest解决方案是一个简单的解决方案,它引用了主项目,但是有很多单元测试(使用NUnit)。

I have setup automatic deployment in Azure. Every time I make a commit on develop it updates one web-app, and when I update master, it updates another web-app. I've done this by setting up the integration to my Github repo here inside the Azure portal:

我在Azure中设置了自动部署。每次我提交开发时,它都会更新一个web应用,当我更新master时,它会更新另一个web应用。我通过在Azure门户中设置了Github repo的集成来实现这一点:

Webapp --> Deployment --> Deployment Options

My question is: how do I run my unit test first?

我的问题是:如何首先运行我的单元测试?

I don't see any options to add this. I don't see any option if I use the newer Continious Delivery (Preview) either.

我看不出有什么办法可以添加这个。如果我使用新的连续交付(预览),我看不到任何选项。

I can see there is an option to add performance tests, but thatis not what I need.

我可以看到添加性能测试的选项,但这不是我需要的。

So my question is two-fold: How do I add these unit tests inside the Azure web portal / updating my build file? And if this is not possible inside Azure, what is the "norm" on how to solve this (very common, I assume) problem?

因此,我的问题是双重的:如何在Azure web门户中添加这些单元测试/更新我的构建文件?如果在Azure中这是不可能的,那么如何解决这个问题(我想这很常见)的“标准”是什么?

1 个解决方案

#1


1  

You can add a custom KUDU script to the root directory of your solution. At that point you have "complete" control over the build and deploy pipeline in Azure. Every web app has a default script in Azure. If you pull your current KUDU script (assuming your are using dotnet core), you should just need to add a dotnet test command before the dotnet publish command and fail accordingly.

您可以向解决方案的根目录添加自定义KUDU脚本。此时,您已经“完全”控制了Azure中的构建和部署管道。每个web应用程序在Azure中都有一个默认的脚本。如果您使用当前的KUDU脚本(假设您使用的是dotnet核心),您只需要在dotnet发布命令之前添加一个dotnet测试命令,并相应地失败。

https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script

https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script

If you have looking for a friendlier alternative, then you can use any number of CI/CD tools outside of Azure. VSTS offers several free build minutes every month.

如果您正在寻找一个更友好的替代方案,那么您可以使用Azure之外的任何数量的CI/CD工具。VSTS每月提供几个免费的构建分钟。

#1


1  

You can add a custom KUDU script to the root directory of your solution. At that point you have "complete" control over the build and deploy pipeline in Azure. Every web app has a default script in Azure. If you pull your current KUDU script (assuming your are using dotnet core), you should just need to add a dotnet test command before the dotnet publish command and fail accordingly.

您可以向解决方案的根目录添加自定义KUDU脚本。此时,您已经“完全”控制了Azure中的构建和部署管道。每个web应用程序在Azure中都有一个默认的脚本。如果您使用当前的KUDU脚本(假设您使用的是dotnet核心),您只需要在dotnet发布命令之前添加一个dotnet测试命令,并相应地失败。

https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script

https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script

If you have looking for a friendlier alternative, then you can use any number of CI/CD tools outside of Azure. VSTS offers several free build minutes every month.

如果您正在寻找一个更友好的替代方案,那么您可以使用Azure之外的任何数量的CI/CD工具。VSTS每月提供几个免费的构建分钟。