Reputation: 9527
Let's say I have a C# ASP.NET Core web app that I'm testing with canopy. I have a canopy project called Test
. Here's how I'd normally go about manually running my canopy tests.
In one PowerShell window I run the web app:
dotnet run
Then in another PowerShell window I run the canopy test project:
dotnet run --project .\Test\Test.fsproj
I then ctrl-c in the first PowerShell window to stop the app.
I wanted a way to do all this in one step from the command line. So I have a PowerShell function test-app
:
function test-app()
{
reset-database
$proc = run_app
run_canopy
Stop-Process $proc.Id
}
reset-database
does just that. 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:
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 = run_app
run_canopy
does the following:
Start-Job
. The job is stored in $job_canopy
.$job_canopy.State
to be 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:
test-app
My question is, what do canopy users typically do to test their apps? 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!
Upvotes: 2
Views: 90
Reputation: 1145
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:
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). But for the quick local development, there's nothing wrong with your approach.
Upvotes: 1