简体   繁体   English

在一个命令行步骤中使用 Canopy 进行测试

[英]Testing with Canopy in one command line step

Context - running tests manually上下文 - 手动运行测试

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 来停止应用程序。

Running tests in one step一步运行测试

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执行以下操作:

  • Starts the canopy project using Start-Job .使用Start-Job启动树冠项目。 The job is stored in $job_canopy .作业存储在$job_canopy中。
  • It waits for canopy to finish by waiting for $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

Question问题

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 本身就是一个应用程序,应该这样对待:

  1. Build an app构建应用程序
  2. Run app's tests (unit tests)运行应用程序的测试(单元测试)
  3. Publish app artifacts发布应用程序工件
  4. Deploy to test environment + start部署到测试环境+启动

The same goes for Canopy天篷也是如此

  1. Build Canopy app构建 Canopy 应用程序
  2. Publish app artifacts发布应用程序工件
  3. Deploy to the environment for running UI tests + run tests部署到运行 UI 测试 + 运行测试的环境

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.

相关问题 是否有可靠的命令行或Powershell步骤格式在TeamCity上运行RSpec测试? - Is there a reliable Command Line or Powershell step format to run RSpec tests on TeamCity? 将Powershell命令结果转换为一行 - Converting Powershell command result to one line 与在构建步骤中执行时相比,在命令行中执行时脚本的结果如何不同 - How does Script has different outcome when executed in command line compared to when executed in build step 如何在一行中设置环境变量并执行命令(PowerShell)? - How to set environment variable and execute command in one line (PowerShell)? 在 powershell 中运行命令并忽略一行中的退出代码 - Run command in powershell and ignore exit code in one line 如何在 powershell 中仅获取 output 命令的一行? - How can I get only one line for output of command in powershell? PowerShell 一行命令显示本地 git 存储库的名称 - PowerShell one line command to display names of local git repositories 使用一个查询的结果作为命令的参数(在单行上) - Use result of one query as argument of a command (on a single line) 如何在 Windows 批处理文件 Z78E6221F6393D135DZ81DB3 中获取 PowerShell 命令的 output 和命令 ECHO 的 output? - How to get output of a PowerShell command and of command ECHO in Windows batch file output on one line? 将批处理命令重写为 Jenkins 构建步骤的 Powershell - Rewrite Batch command as Powershell for Jenkins build step
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM