Permalink
Browse files

Fixes parameterized tests so that when parameters are unknown, the te…

…st fails with a clear message.
  • Loading branch information...
1 parent 890673d commit 006f3a74e0f47222e1e44b8f192d44d70172a788 @plioi plioi committed Oct 11, 2013
Showing with 24 additions and 4 deletions.
  1. +24 −4 src/Fixie/Conventions/Convention.cs
@@ -17,7 +17,7 @@ public Convention()
InstanceExecution = new InstanceBehaviorBuilder();
ClassExecution = new TypeBehaviorBuilder().CreateInstancePerCase();
- methodCallParameterBuilder = method => new[] { (object[])null };
+ methodCallParameterBuilder = method => new object[][] { };
}
public ClassFilter Classes { get; private set; }
@@ -37,9 +37,7 @@ public void Execute(Listener listener, params Type[] candidateTypes)
{
var methods = Methods.Filter(testClass);
- var cases = methods.SelectMany(method =>
- methodCallParameterBuilder(method).Select(parameters =>
- new Case(testClass, method, parameters))).ToArray();
+ var cases = methods.SelectMany(method => CasesForMethod(testClass, method)).ToArray();
ClassExecution.Behavior.Execute(testClass, this, cases);
@@ -54,5 +52,27 @@ public void Execute(Listener listener, params Type[] candidateTypes)
}
}
}
+
+ IEnumerable<Case> CasesForMethod(Type testClass, MethodInfo method)
+ {
+ var casesForKnownInputParameters = methodCallParameterBuilder(method)
+ .Select(parameters => new Case(testClass, method, parameters));
+
+ bool any = false;
+
+ foreach (var actualCase in casesForKnownInputParameters)
+ {
+ any = true;
+ yield return actualCase;
+ }
+
+ if (!any)
+ {
+ if (method.GetParameters().Any())
+ yield return new UncallableParameterizedCase(testClass, method);
+ else
+ yield return new Case(testClass, method);
+ }
+ }
}
}

0 comments on commit 006f3a7

Please sign in to comment.