Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,21 @@ This provides a proxy server application of Azure OpenAI Service API that round-
--parameters environmentName=$AZURE_ENV_NAME `
--parameters location=$AZURE_LOCATION
```

## Unit Testing & Integration Testing

1. Run the following command to run both unit tests and integration tests at once on your local machine.

```bash
# zsh/bash
./scripts/run-tests.sh -c Debug

# PowerShell
./scripts/Run-Tests.ps1 -Configuration Debug
```

> **NOTE**: While running the integration tests using the script above, you might be seeing the error like
>
> `System.IO.IOException: Failed to bind to address https://127.0.0.1:22000: address already in use.`
>
> It can sometimes happen. However, it doesn't impact on the test results.
60 changes: 60 additions & 0 deletions scripts/Run-Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Run unit tests and integration tests
Param(
[string]
[Parameter(Mandatory=$false)]
[ValidateSet("Debug", "Release")]
$Configuration = "Debug",

[switch]
[Parameter(Mandatory=$false)]
$Help
)

function Show-Usage {
Write-Host " This runs both unit tests and integration tests.

Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) ``
[-Configuration <Configuration>] ``

[-Help]

Options:
-Configuration Configuration. Possible values are 'Debug' or 'Release'. Default is 'Debug'.

-Help: Show this message.
"

Exit 0
}

# Builds apps
Write-Host "Building apps..." -ForegroundColor Cyan

dotnet restore
dotnet build -c $Configuration

# Runs unit tests
Write-Host "Invoking unit tests..." -ForegroundColor Cyan

dotnet test ./test/AzureOpenAIProxy.AppHost.Tests -c $Configuration --no-build --logger "trx" --collect:"XPlat Code Coverage"
dotnet test ./test/AzureOpenAIProxy.ApiApp.Tests -c $Configuration --no-build --logger "trx" --collect:"XPlat Code Coverage"

# Runs integration tests
Write-Host "Invoking integration tests..." -ForegroundColor Cyan

$playwright = Get-ChildItem -File Microsoft.Playwright.dll -Path . -Recurse
$installer = "$($playwright[0].Directory.FullName)/playwright.ps1"
& "$installer" install

Start-Process -NoNewWindow "dotnet" @("run", "--project", "./src/AzureOpenAIProxy.AppHost", "--no-build")
Start-Sleep -s 30

dotnet test ./test/AzureOpenAIProxy.PlaygroundApp.Tests -c $Configuration --logger "trx" --collect:"XPlat Code Coverage"

# Cleans up
$process = if ($IsWindows -eq $true) {
Get-Process | Where-Object { $_.ProcessName -eq "AzureOpenAIProxy.AppHost" }
} else {
Get-Process | Where-Object { $_.Path -like "*AzureOpenAIProxy.AppHost" }
}
Stop-Process -Id $process.Id
71 changes: 71 additions & 0 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
# Run unit tests and integration tests

set -e

# Function to show usage
usage() {
echo " This runs both unit tests and integration tests.

Usage: $0 [-c|--config|--configuration <Configuration>] [-h|--help]

Options:
-c|--config|--configuration Configuration. Possible values are 'Debug' or 'Release'. Default is 'Debug'.
-h|--help Show this message.
"
exit 0
}

# Default configuration
CONFIGURATION="Debug"

if [[ $# -eq 0 ]]; then
CONFIGURATION="Debug"
fi

while [[ "$1" != "" ]]; do
case $1 in
-c | --config | --configuration)
shift
CONFIGURATION="$1"
;;

-h | --help)
usage
exit 0
;;

*)
usage
exit 0
;;
esac

shift
done

# Builds apps
echo -e "\033[36mBuilding apps...\033[0m"

dotnet restore
dotnet build -c $CONFIGURATION

# Runs unit tests
echo -e "\033[36mInvoking unit tests...\033[0m"

dotnet test ./test/AzureOpenAIProxy.AppHost.Tests -c $CONFIGURATION --no-build --logger "trx" --collect:"XPlat Code Coverage"
dotnet test ./test/AzureOpenAIProxy.ApiApp.Tests -c $CONFIGURATION --no-build --logger "trx" --collect:"XPlat Code Coverage"

# Runs integration tests
echo -e "\033[36mInvoking integration tests...\033[0m"

pwsh ./test/AzureOpenAIProxy.PlaygroundApp.Tests/bin/Debug/net8.0/playwright.ps1 install

dotnet run --project ./src/AzureOpenAIProxy.AppHost --no-build &
APP_PID=$!
sleep 30

dotnet test ./test/AzureOpenAIProxy.PlaygroundApp.Tests -c $CONFIGURATION --logger "trx" --collect:"XPlat Code Coverage"

# Cleans up
kill $APP_PID