summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs')
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs99
1 files changed, 61 insertions, 38 deletions
diff --git a/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs b/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs
index b2f98e24..78fa2e3d 100644
--- a/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs
+++ b/Xamarin.Forms.Core.iOS.UITests/BaseTestFixture.cs
@@ -16,67 +16,90 @@ namespace Xamarin.Forms.Core.UITests
{
// TODO: Landscape tests
- public static IApp App { get; private set; }
+ public static IApp App { get; set; }
public string PlatformViewType { get; protected set; }
- public bool ShouldResetPerFixture { get; protected set; }
- public AppRect ScreenBounds { get; private set; }
+ public static AppRect ScreenBounds { get; set; }
- protected BaseTestFixture()
+ [TestFixtureTearDown]
+ protected virtual void FixtureTeardown()
{
- ShouldResetPerFixture = true;
}
- protected abstract void NavigateToGallery();
+ static int s_testsrun;
+ const int ConsecutiveTestLimit = 40;
-#pragma warning disable 618
- [TestFixtureSetUp]
-#pragma warning restore 618
- protected virtual void FixtureSetup()
+ // Until we get more of our memory leak issues worked out, restart the app
+ // after a specified number of tests so we don't get bogged down in GC
+ public void EnsureMemory()
{
- try
- {
- if (ShouldResetPerFixture)
- {
- RelaunchApp();
- }
- }
- catch (Exception ex)
+ s_testsrun += 1;
+
+ if (s_testsrun >= ConsecutiveTestLimit)
{
- Debug.WriteLine(ex);
- throw;
- }
- }
+ s_testsrun = 0;
-#pragma warning disable 618
- [TestFixtureTearDown]
-#pragma warning restore 618
- protected virtual void FixtureTeardown()
- {
+ CoreUITestsSetup.LaunchApp();
+
+ FixtureSetup();
+ }
}
[SetUp]
protected virtual void TestSetup()
{
- if (!ShouldResetPerFixture)
- {
-
- RelaunchApp();
- }
+ EnsureMemory();
}
[TearDown]
protected virtual void TestTearDown()
{
-
}
- void RelaunchApp()
+ protected abstract void NavigateToGallery();
+
+#pragma warning disable 618
+ [TestFixtureSetUp]
+#pragma warning restore 618
+ protected virtual void FixtureSetup()
{
- App = null;
- App = AppSetup.Setup();
- App.SetOrientationPortrait();
- ScreenBounds = App.RootViewRect();
+ ResetApp();
NavigateToGallery();
}
+
+ protected void ResetApp()
+ {
+#if __IOS__
+ App.Invoke("reset:", string.Empty);
+#endif
+#if __ANDROID__
+ App.Invoke("Reset");
+#endif
+ }
+ }
+}
+
+#if UITEST
+namespace Xamarin.Forms.Core.UITests
+{
+ using NUnit.Framework;
+
+ [SetUpFixture]
+ public class CoreUITestsSetup
+ {
+ [SetUp]
+ public void RunBeforeAnyTests()
+ {
+ LaunchApp();
+ }
+
+ public static void LaunchApp()
+ {
+ BaseTestFixture.App = null;
+ BaseTestFixture.App = AppSetup.Setup();
+
+ BaseTestFixture.App.SetOrientationPortrait();
+ BaseTestFixture.ScreenBounds = BaseTestFixture.App.RootViewRect();
+ }
}
}
+#endif