[英]Testing with Canopy in one command line step
Let's say I have a C# ASP.NET Core web app that I'm testing with canopy .假设我有一个 C# ASP.NET Core web 应用程序,我正在使用canopy进行测试。 I have a canopy project called Test
.我有一个名为Test
的树冠项目。 Here's how I'd normally go about manually running my canopy tests.以下是我通常如何手动运行我的树冠测试的 go。
In one PowerShell window I run the web app:在一个 PowerShell window 我运行 web 应用程序:
dotnet run
Then in another PowerShell window I run the canopy test project:然后在另一个 PowerShell window 我运行树冠测试项目:
dotnet run --project .\Test\Test.fsproj
I then ctrl-c in the first PowerShell window to stop the app.然后我在第一个 PowerShell window 中按 ctrl-c 来停止应用程序。
I wanted a way to do all this in one step from the command line.我想要一种从命令行一步完成所有这些的方法。 So I have a PowerShell function test-app
:所以我有一个 PowerShell function test-app
:
function test-app()
{
reset-database
$proc = run_app
run_canopy
Stop-Process $proc.Id
}
reset-database
does just that. reset-database
就是这样做的。 It resets the database so that the tests run in a clean environment:它重置数据库,以便测试在干净的环境中运行:
function reset-database ()
{
dotnet ef database drop -f
dotnet ef database update
}
run_app
takes care of running the app: run_app
负责运行应用程序:
function run_app ()
{
$items = 'dotnet run' -split ' '
Start-Process $items[0] $items[1..100] -PassThru
}
It returns a process that is stored in $proc
:它返回一个存储在$proc
中的进程:
$proc = run_app
run_canopy
does the following: run_canopy
执行以下操作:
Start-Job
.使用Start-Job
启动树冠项目。 The job is stored in $job_canopy
.作业存储在$job_canopy
中。$job_canopy.State
to be Completed
它通过等待$job_canopy.State
完成来等待树冠Completed
function run_canopy ()
{
$dir = (Resolve-Path .).Path
$code = {
param($dir)
cd $dir
dotnet run --project .\Test\Test.fsproj
}
$job_canopy = Start-Job -ScriptBlock $code -ArgumentList $dir
while ($job_canopy.State -ne 'Completed')
{
Start-Sleep -Seconds 2
}
Receive-Job $job_canopy
}
Finally, the app is then stopped:最后,应用程序停止:
Stop-Process $proc.Id
So far, this has been working pretty well.到目前为止,这一直运作良好。 If I want to test the web app, all I have to do is run:如果我想测试 web 应用程序,我所要做的就是运行:
test-app
My question is, what do canopy users typically do to test their apps?我的问题是,canopy 用户通常会做什么来测试他们的应用程序? Do you just take the manual approach of "run the app" then "run the tests"?你只是采取“运行应用程序”然后“运行测试”的手动方法吗? Do you have some automated approach similar to the above?你有一些类似于上面的自动化方法吗? Is there a better way that is commonly used?有没有更好的常用方法?
Thanks for any suggestions!感谢您的任何建议!
Your approach is pretty smart and I like it for local development where you can run app AND tests using a single command.您的方法非常聪明,我喜欢它用于本地开发,您可以使用单个命令运行应用程序和测试。 However, for CI/CD pipeline, I would suggest having it in separate steps - Canopy is an application by itself and should be treated like that:但是,对于 CI/CD 管道,我建议将其分成单独的步骤 - Canopy 本身就是一个应用程序,应该这样对待:
The same goes for Canopy天篷也是如此
Separation of lifecycle/deployment processes between tested app and Canopy can help you when working in larger teams with separated responsibilities (Development, QA).在具有分离职责(开发、质量保证)的大型团队中工作时,测试应用程序和 Canopy 之间的生命周期/部署过程分离可以帮助您。 But for the quick local development, there's nothing wrong with your approach.但是为了快速的本地开发,您的方法没有错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.