Skip to content

Commit c9ac13f

Browse files
committed
Address third round of PR review comments
- Add 'VSTest version' assertion to confirm VSTest runner is used - Replace vacuous Assert.IsNotNull(MainWindow) with ControlType.Window check in sample - Add final AppProcess.Refresh() before post-loop MainWindowHandle check - Widen teardown catch to include Win32Exception for inaccessible processes - Replace UseWPF with FrameworkReference to Microsoft.WindowsDesktop.App - Update MSTest.Sdk expected file count (15 -> 16) for WindowsAppTesting.targets
1 parent ae139d7 commit c9ac13f

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

eng/verify-nupkgs.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Unzip {
1919
function Confirm-NugetPackages {
2020
Write-Verbose "Starting Confirm-NugetPackages."
2121
$expectedNumOfFiles = @{
22-
"MSTest.Sdk" = 15
22+
"MSTest.Sdk" = 16
2323
"MSTest.TestFramework" = 105
2424
"MSTest.TestAdapter" = 49
2525
"MSTest" = 10

samples/public/DemoMSTestSdk/ProjectUsingWindowsAppTesting/CalculatorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public void Calculator_MainWindow_HasExpectedTitle()
3232
{
3333
// The MainWindow property is automatically populated by WindowTest
3434
// after launching the application specified by ApplicationPath.
35-
Assert.IsNotNull(MainWindow);
35+
Assert.AreEqual(ControlType.Window, MainWindow.Current.ControlType,
36+
"Expected the main window element to be of control type Window.");
3637

3738
string title = MainWindow.Current.Name;
3839
Assert.IsFalse(

src/TestFramework/TestFramework.Windows.AppTesting/ApplicationTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.ComponentModel;
45
using System.Diagnostics;
56

67
namespace Microsoft.MSTest.Windows.AppTesting;
@@ -90,6 +91,7 @@ public void ApplicationSetup()
9091
}
9192
}
9293

94+
AppProcess.Refresh();
9395
if (AppProcess.MainWindowHandle == IntPtr.Zero)
9496
{
9597
throw new TimeoutException(
@@ -118,9 +120,9 @@ public void ApplicationTearDown()
118120
_ = appProcess.WaitForExit(5000);
119121
}
120122
}
121-
catch (InvalidOperationException)
123+
catch (Exception ex) when (ex is InvalidOperationException or Win32Exception)
122124
{
123-
// The process exited between state checks and shutdown operations.
125+
// The process exited or became inaccessible between state checks and shutdown operations.
124126
}
125127
}
126128
}

src/TestFramework/TestFramework.Windows.AppTesting/TestFramework.Windows.AppTesting.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
<PropertyGroup>
44
<TargetFrameworks>net8.0-windows;net9.0-windows</TargetFrameworks>
55
<EnableWindowsTargeting Condition=" '$(OS)' != 'Windows_NT' ">true</EnableWindowsTargeting>
6-
<UseWPF>true</UseWPF>
76
</PropertyGroup>
87

8+
<ItemGroup>
9+
<FrameworkReference Include="Microsoft.WindowsDesktop.App" />
10+
</ItemGroup>
11+
912
<PropertyGroup>
1013
<IsPackable>true</IsPackable>
1114
<PackageId>MSTest.Windows.AppTesting</PackageId>

test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsAppTestingSdkTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public async Task EnableWindowsAppTesting_WhenUsingVSTest_RunsDesktopTests()
3939
cancellationToken: TestContext.CancellationToken);
4040

4141
dotnetTestResult.AssertExitCodeIs(0);
42+
dotnetTestResult.AssertOutputContains("VSTest version");
4243
dotnetTestResult.AssertOutputContains("Passed! - Failed: 0, Passed: 2, Skipped: 0, Total: 2");
4344
}
4445

0 commit comments

Comments
 (0)