From 60683e0b204c8331f9e2ef698bf6850478ec5b0b Mon Sep 17 00:00:00 2001 From: scoban Date: Wed, 27 Sep 2023 04:20:05 -0700 Subject: [PATCH] Log test start/stop times (#17675) --- .../UITests/Tests/CoreGalleryBasePageTest.cs | 4 +-- .../UITests/Tests/Issues/_IssuesUITest.cs | 4 +-- .../tests/UITests/Tests/UITestBase.cs | 26 +++++++++++++++++-- .../TestUtils.Appium.UITests/AppiumContext.cs | 4 +-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Controls/tests/UITests/Tests/CoreGalleryBasePageTest.cs b/src/Controls/tests/UITests/Tests/CoreGalleryBasePageTest.cs index 09a5a8c347f6..ab01af7e1909 100644 --- a/src/Controls/tests/UITests/Tests/CoreGalleryBasePageTest.cs +++ b/src/Controls/tests/UITests/Tests/CoreGalleryBasePageTest.cs @@ -20,7 +20,7 @@ protected override void FixtureSetup() } catch (Exception e) { - TestContext.Error.WriteLine($">>>>> The FixtureSetup threw an exception. Attempt {retries}/{SetupMaxRetries}.{Environment.NewLine}Exception details: {e}"); + TestContext.Error.WriteLine($">>>>> {DateTime.Now} The FixtureSetup threw an exception. Attempt {retries}/{SetupMaxRetries}.{Environment.NewLine}Exception details: {e}"); if (retries++ < SetupMaxRetries) { Reset(); @@ -43,7 +43,7 @@ protected override void FixtureTeardown() catch (Exception e) { var name = TestContext.CurrentContext.Test.MethodName ?? TestContext.CurrentContext.Test.Name; - TestContext.Error.WriteLine($">>>>> The FixtureTeardown threw an exception during {name}.{Environment.NewLine}Exception details: {e}"); + TestContext.Error.WriteLine($">>>>> {DateTime.Now} The FixtureTeardown threw an exception during {name}.{Environment.NewLine}Exception details: {e}"); } } diff --git a/src/Controls/tests/UITests/Tests/Issues/_IssuesUITest.cs b/src/Controls/tests/UITests/Tests/Issues/_IssuesUITest.cs index a8b98975d2e5..0d7eece3a5f7 100644 --- a/src/Controls/tests/UITests/Tests/Issues/_IssuesUITest.cs +++ b/src/Controls/tests/UITests/Tests/Issues/_IssuesUITest.cs @@ -21,7 +21,7 @@ protected override void FixtureSetup() } catch (Exception e) { - TestContext.Error.WriteLine($">>>>> The FixtureSetup threw an exception. Attempt {retries}/{SetupMaxRetries}.{Environment.NewLine}Exception details: {e}"); + TestContext.Error.WriteLine($">>>>> {DateTime.Now} The FixtureSetup threw an exception. Attempt {retries}/{SetupMaxRetries}.{Environment.NewLine}Exception details: {e}"); if (retries++ < SetupMaxRetries) { Reset(); @@ -45,7 +45,7 @@ protected override void FixtureTeardown() catch (Exception e) { var name = TestContext.CurrentContext.Test.MethodName ?? TestContext.CurrentContext.Test.Name; - TestContext.Error.WriteLine($">>>>> The FixtureTeardown threw an exception during {name}.{Environment.NewLine}Exception details: {e}"); + TestContext.Error.WriteLine($">>>>> {DateTime.Now} The FixtureTeardown threw an exception during {name}.{Environment.NewLine}Exception details: {e}"); } } diff --git a/src/Controls/tests/UITests/Tests/UITestBase.cs b/src/Controls/tests/UITests/Tests/UITestBase.cs index cfe38d823232..5ea3541c454e 100644 --- a/src/Controls/tests/UITests/Tests/UITestBase.cs +++ b/src/Controls/tests/UITests/Tests/UITestBase.cs @@ -49,9 +49,31 @@ public UITestBase(TestDevice device) _visualTestContext = new VisualTestContext(); } - protected virtual void FixtureSetup() { } + [SetUp] + public void RecordTestSetup() + { + var name = TestContext.CurrentContext.Test.MethodName ?? TestContext.CurrentContext.Test.Name; + TestContext.Progress.WriteLine($">>>>> {DateTime.Now} {name} Start"); + } + + [TearDown] + public void RecordTestTeardown() + { + var name = TestContext.CurrentContext.Test.MethodName ?? TestContext.CurrentContext.Test.Name; + TestContext.Progress.WriteLine($">>>>> {DateTime.Now} {name} Stop"); + } - protected virtual void FixtureTeardown() { } + protected virtual void FixtureSetup() + { + var name = TestContext.CurrentContext.Test.MethodName ?? TestContext.CurrentContext.Test.Name; + TestContext.Progress.WriteLine($">>>>> {DateTime.Now} {nameof(FixtureSetup)} for {name}"); + } + + protected virtual void FixtureTeardown() + { + var name = TestContext.CurrentContext.Test.MethodName ?? TestContext.CurrentContext.Test.Name; + TestContext.Progress.WriteLine($">>>>> {DateTime.Now} {nameof(FixtureTeardown)} for {name}"); + } [TearDown] public void UITestBaseTearDown() diff --git a/src/TestUtils/src/TestUtils.Appium.UITests/AppiumContext.cs b/src/TestUtils/src/TestUtils.Appium.UITests/AppiumContext.cs index ca8ba732e7f1..7175c7bf5e82 100644 --- a/src/TestUtils/src/TestUtils.Appium.UITests/AppiumContext.cs +++ b/src/TestUtils/src/TestUtils.Appium.UITests/AppiumContext.cs @@ -72,7 +72,7 @@ public UITestContext CreateUITestContext(TestConfig testConfig) { if (_server == null || !_server.IsRunning) { - TestContext.Error.WriteLine($">>>>> Server was not running when calling {nameof(CreateUITestContext)}, starting it ourselves..."); + TestContext.Error.WriteLine($">>>>> {DateTime.Now} Server was not running when calling {nameof(CreateUITestContext)}, starting it ourselves..."); CreateAndStartServer(); } } @@ -109,7 +109,7 @@ public UITestContext CreateUITestContext(TestConfig testConfig) // Default command timeout is 60 seconds when executing the NewSessionCommand if (retries++ < 10) { - TestContext.Error.WriteLine($">>>>> Retrying to create the driver, attempt #{retries}"); + TestContext.Error.WriteLine($">>>>> {DateTime.Now} Retrying to create the driver, attempt #{retries}"); } else {