Context - running tests manually
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.
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
:
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:
- Starts the canopy project using
Start-Job
. The job is stored in$job_canopy
. - It waits for canopy to finish by waiting for
$job_canopy.State
to beCompleted
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
Question
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!