-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathrun_playmode_tests.ps1
91 lines (82 loc) · 2.95 KB
/
run_playmode_tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright (c) Mixed Reality Toolkit Contributors
# Licensed under the BSD 3-Clause
<#
# Runs the playmode tests in batch mode. This is the same technique as
# used by the MRTK PR validation when you do "/azp run mrtk_pr" on github.
#>
param(
# Path to your Unity project
[Parameter(Position = 0)]
[ValidateScript({ Test-Path $_ -PathType Container })]
[string]
$projectPath = "$PSScriptRoot/../../UnityProjects/MRTKDevTemplate/",
# Folder that will contain test results output and logs
[string]
[ValidateScript({ Test-Path $_ -PathType Container })]
$outFolder = "$PSScriptRoot/out/",
# Unity version override
[Parameter(Mandatory = $false)]
[string]
$unityVersion = "2021.3.21f1",
# Path to your Unity Executable
[ValidateScript({ [System.IO.File]::Exists($_) -and $_.EndsWith(".exe") })]
[string]
$unityExePath = "C:\Program Files\Unity\Hub\Editor\$unityVersion\Editor\Unity.exe",
# Optional test filter
[Parameter(Mandatory = $false)]
[string]
$editorTestsFilter = ""
)
$dateStr = Get-Date -format "yyyy_MM_dd-HHmmss"
if (-not (Test-Path $outFolder)) {
New-Item -ItemType Directory $outFolder
}
$logPath = "$outFolder\playmode_tests_log-$dateStr.log"
$testResultPath = "$outFolder\playmode_tests_result-$dateStr.xml"
$timer = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host "Starting test run"
Write-Host "Writing test output to $logPath...`n"
$unityArgs = @(
"-runTests",
"-testPlatform playmode"
"-batchmode",
"-editorTestsResultFile $testResultPath",
"-logFile $logPath",
"-projectPath $projectPath",
"-editorTestsFilter $editorTestsFilter"
)
Write-Host "Running command:"
Write-Host $unityExePath ($unityArgs -Join " ")
$handle = Start-Process -FilePath $unityExePath -PassThru -ArgumentList $unityArgs
Start-Process pwsh -ArgumentList @(
"-command",
"Get-Content $logPath -Wait")
Write-Host "`nOpening new window to view test output..."
Write-Host "Results will be printed here when the test completes"
while (-not $handle.HasExited) {
Start-Sleep 3
}
Write-Host "`nTest completed! Results written to $testResultPath"
Write-Host -ForegroundColor Cyan "`nTest results:"
Write-Host -ForegroundColor Cyan "Tests took: $($timer.Elapsed)"
[xml]$cn = Get-Content $testResultPath
$cnx = $cn["test-run"]
Write-Host -ForegroundColor Cyan "passed: $($cnx.passed) failed: $($cnx.failed)"
if ($cnx.failed -gt 0) {
Write-Host ""
Write-Host -ForegroundColor Cyan "Failed tests:"
$testcases = $cnx.GetElementsByTagName("test-case")
foreach ($item in $testcases) {
if ($item.result -eq "Failed") {
Write-Host "$($item.classname)::$($item.name)"
}
}
Write-Host ""
Write-Host -ForegroundColor Cyan "Skipped tests:"
$testcases = $cnx.GetElementsByTagName("test-case")
foreach ($item in $testcases) {
if ($item.result -eq "Skipped") {
Write-Host "$($item.classname)::$($item.name)"
}
}
}