Browse files

Modified UnitTestDetector to make testing easier. Wrote two tests dem…

…onstrating the issue with UnitTestDetector giving false positives
  • Loading branch information...
1 parent d3fed5b commit 7d8d95234c044eb266821709a1e25bc1945309f1 @ArturPhilibin ArturPhilibin committed with paulcbetts Feb 8, 2013
Showing with 86 additions and 24 deletions.
  1. +56 −0 ReactiveUI.Tests/RxAppTest.cs
  2. +30 −24 ReactiveUI/RxApp.cs
View
56 ReactiveUI.Tests/RxAppTest.cs
@@ -25,5 +25,61 @@ public void SchedulerShouldBeImmediateInTestRunner()
Console.WriteLine(RxApp.DeferredScheduler.GetType().FullName);
Assert.Equal(Scheduler.Immediate, RxApp.DeferredScheduler);
}
+
+ [Fact]
+ public void UnitTestDetectorIdentifiesThisTestAsAnXUnitTest()
+ {
+ string[] testAssemblies = new[] {
+ "CSUNIT",
+ "NUNIT",
+ "XUNIT",
+ "MBUNIT",
+ "TESTDRIVEN",
+ "QUALITYTOOLS.TIPS.UNITTEST.ADAPTER",
+ "QUALITYTOOLS.UNITTESTING.SILVERLIGHT",
+ "PEX",
+ "MSBUILD",
+ "NBEHAVE",
+ "TESTPLATFORM",
+ };
+
+ string[] designEnvironments = new[] {
+ "BLEND.EXE",
+ "MONODEVELOP",
+ "SHARPDEVELOP.EXE",
+ };
+
+ var isInUnitTestRunner = RealUnitTestDetector.InUnitTestRunner(testAssemblies, designEnvironments);
+
+ Assert.True(isInUnitTestRunner);
+ }
+
+ [Fact]
+ public void UnitTestDetectorDoesNotIdentifyThisTestWhenXUnitAssemblyNotChecked()
+ {
+ // XUnit assembly name removed
+ string[] testAssembliesWithoutNunit = new[] {
+ "CSUNIT",
+ "NUNIT",
+ "MBUNIT",
+ "TESTDRIVEN",
+ "QUALITYTOOLS.TIPS.UNITTEST.ADAPTER",
+ "QUALITYTOOLS.UNITTESTING.SILVERLIGHT",
+ "PEX",
+ "MSBUILD",
+ "NBEHAVE",
+ "TESTPLATFORM",
+ };
+
+ string[] designEnvironments = new[] {
+ "BLEND.EXE",
+ "MONODEVELOP",
+ "SHARPDEVELOP.EXE",
+ };
+
+ var isInUnitTestRunner = RealUnitTestDetector.InUnitTestRunner(testAssembliesWithoutNunit, designEnvironments);
+
+ Assert.False(isInUnitTestRunner);
+ }
}
}
View
54 ReactiveUI/RxApp.cs
@@ -427,30 +427,8 @@ public class NullDefaultPropertyBindingProvider : IDefaultPropertyBindingProvide
internal static class RealUnitTestDetector
{
- public static bool InUnitTestRunner()
+ public static bool InUnitTestRunner(string[] testAssemblies, string[] designEnvironments)
{
- // XXX: This is hacky and evil, but I can't think of any better way
- // to do this
- string[] testAssemblies = new[] {
- "CSUNIT",
- "NUNIT",
- "XUNIT",
- "MBUNIT",
- "TESTDRIVEN",
- "QUALITYTOOLS.TIPS.UNITTEST.ADAPTER",
- "QUALITYTOOLS.UNITTESTING.SILVERLIGHT",
- "PEX",
- "MSBUILD",
- "NBEHAVE",
- "TESTPLATFORM",
- };
-
- string[] designEnvironments = new[] {
- "BLEND.EXE",
- "MONODEVELOP",
- "SHARPDEVELOP.EXE",
- };
-
#if SILVERLIGHT
// NB: Deployment.Current.Parts throws an exception when accessed in Blend
try {
@@ -492,7 +470,8 @@ public static bool InUnitTestRunner()
// without access to any WPF references :-/
var entry = Assembly.GetEntryAssembly();
var exeName = (entry != null ? entry.Location.ToUpperInvariant() : "");
- if (designEnvironments.Any(x => x.Contains(exeName))) {
+ if (designEnvironments.Any(x => x.Contains(exeName)))
+ {
return true;
}
@@ -501,6 +480,33 @@ public static bool InUnitTestRunner()
#endif
}
+ public static bool InUnitTestRunner()
+ {
+ // XXX: This is hacky and evil, but I can't think of any better way
+ // to do this
+ string[] testAssemblies = new[] {
+ "CSUNIT",
+ "NUNIT",
+ "XUNIT",
+ "MBUNIT",
+ "TESTDRIVEN",
+ "QUALITYTOOLS.TIPS.UNITTEST.ADAPTER",
+ "QUALITYTOOLS.UNITTESTING.SILVERLIGHT",
+ "PEX",
+ "MSBUILD",
+ "NBEHAVE",
+ "TESTPLATFORM",
+ };
+
+ string[] designEnvironments = new[] {
+ "BLEND.EXE",
+ "MONODEVELOP",
+ "SHARPDEVELOP.EXE",
+ };
+
+ return InUnitTestRunner(testAssemblies, designEnvironments);
+ }
+
}
}

0 comments on commit 7d8d952

Please sign in to comment.