Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

inform listener about skipped cases

  • Loading branch information...
commit 9878d984a007791b7f1f3898cdb05098ade79921 1 parent 47ded46
@mexx authored
View
9 src/Fixie.TestDriven/TestDrivenListener.cs
@@ -16,6 +16,15 @@ public void AssemblyStarted(Assembly assembly)
{
}
+ public void CaseSkipped(Case @case)
+ {
+ tdnet.TestFinished(new TestResult
+ {
+ Name = @case.Name,
+ State = TestState.Ignored
+ });
+ }
+
public void CasePassed(PassResult result)
{
var @case = result.Case;
View
15 src/Fixie.Tests/Conventions/ConventionTests.cs
@@ -161,12 +161,13 @@ public void ShouldExecuteAllCasesInAllDiscoveredTestClasses()
var listener = new StubListener();
var convention = new SelfTestConvention();
- convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass));
+ convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass), typeof(SkipTestClass));
listener.Entries.ShouldEqual("Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassA passed.",
"Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassB passed.",
"Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Fail failed: 'Fail' failed!",
- "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.");
+ "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.",
+ "Fixie.Tests.Conventions.ConventionTests+SkipTestClass.Skip skipped.");
}
public void ShouldAllowRandomShufflingOfCaseExecutionOrder()
@@ -178,12 +179,13 @@ public void ShouldAllowRandomShufflingOfCaseExecutionOrder()
.CreateInstancePerTestClass()
.ShuffleCases(new Random(1));
- convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass));
+ convention.Execute(listener, typeof(SampleIrrelevantClass), typeof(PassTestClass), typeof(int), typeof(PassFailTestClass), typeof(SkipTestClass));
listener.Entries.ShouldEqual("Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassB passed.",
"Fixie.Tests.Conventions.ConventionTests+PassTestClass.PassA passed.",
"Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Fail failed: 'Fail' failed!",
- "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.");
+ "Fixie.Tests.Conventions.ConventionTests+PassFailTestClass.Pass passed.",
+ "Fixie.Tests.Conventions.ConventionTests+SkipTestClass.Skip skipped.");
}
class SampleIrrelevantClass
@@ -203,5 +205,10 @@ class PassFailTestClass
public void Pass() { }
public void Fail() { throw new FailureException(); }
}
+
+ class SkipTestClass
+ {
+ public void Skip() { throw new ShouldBeUnreachableException(); }
+ }
}
}
View
68 src/Fixie.Tests/Lifecycle/ConstructionTests.cs
@@ -150,6 +150,74 @@ public void ShouldFailAllCasesWhenConstructingPerTestClassAndCustomFactoryThrows
"Factory");
}
+ public void ShouldSkipConstructingPerCaseWhenAllCasesSkipped()
+ {
+ Convention.ClassExecution
+ .CreateInstancePerCase();
+
+ Convention.CaseExecution
+ .Skip(x => true);
+
+ var output = Run();
+
+ output.ShouldHaveResults(
+ "SampleTestClass.Pass skipped.",
+ "SampleTestClass.Fail skipped.");
+
+ output.ShouldHaveLifecycle();
+ }
+
+ public void ShouldSkipConstructingPerTestClassWhenAllCasesSkipped()
+ {
+ Convention.ClassExecution
+ .CreateInstancePerTestClass();
+
+ Convention.CaseExecution
+ .Skip(x => true);
+
+ var output = Run();
+
+ output.ShouldHaveResults(
+ "SampleTestClass.Pass skipped.",
+ "SampleTestClass.Fail skipped.");
+
+ output.ShouldHaveLifecycle();
+ }
+
+ public void ShouldSkipConstructingPerCaseUsingCustomFactoryWhenAllCasesSkipped()
+ {
+ Convention.ClassExecution
+ .CreateInstancePerCase(Factory);
+
+ Convention.CaseExecution
+ .Skip(x => true);
+
+ var output = Run();
+
+ output.ShouldHaveResults(
+ "SampleTestClass.Pass skipped.",
+ "SampleTestClass.Fail skipped.");
+
+ output.ShouldHaveLifecycle();
+ }
+
+ public void ShouldSkipConstructingPerTestClassUsingCustomFactoryWhenAllCasesSkipped()
+ {
+ Convention.ClassExecution
+ .CreateInstancePerTestClass(Factory);
+
+ Convention.CaseExecution
+ .Skip(x => true);
+
+ var output = Run();
+
+ output.ShouldHaveResults(
+ "SampleTestClass.Pass skipped.",
+ "SampleTestClass.Fail skipped.");
+
+ output.ShouldHaveLifecycle();
+ }
+
static object Factory(Type testClass)
{
WhereAmI();
View
3  src/Fixie.Tests/Listeners/ConsoleListenerTests.cs
@@ -22,6 +22,7 @@ public void ShouldReportResultsToTheConsole()
console.Lines()
.Select(x => Regex.Replace(x, @":line \d+", ":line #")) //Avoid brittle assertion introduced by stack trace line numbers.
.ShouldEqual(
+ "Test '" + testClass + ".SkipA' skipped",
"Console.Out: FailA",
"Console.Error: FailA",
"Console.Out: FailB",
@@ -70,6 +71,8 @@ public void FailB()
public void PassC() { WhereAmI(); }
+ public void SkipA() { throw new ShouldBeUnreachableException(); }
+
static void WhereAmI([CallerMemberName] string member = null)
{
Console.Out.WriteLine("Console.Out: " + member);
View
4 src/Fixie.Tests/Listeners/TeamCityListenerTests.cs
@@ -23,6 +23,8 @@ public void ShouldReportResultsToTheConsoleInTeamCityFormat()
.Select(x => Regex.Replace(x, @":line \d+", ":line #")) //Avoid brittle assertion introduced by stack trace line numbers.
.Select(x => Regex.Replace(x, @"duration='\d+'", "duration='#'")) //Avoid brittle assertion introduced by durations.
.ShouldEqual(
+ "##teamcity[testIgnored name='" + testClass + ".SkipA']",
+
"Console.Out: FailA",
"Console.Error: FailA",
"Console.Out: FailB",
@@ -83,6 +85,8 @@ public void FailB()
public void PassC() { WhereAmI(); }
+ public void SkipA() { throw new ShouldBeUnreachableException(); }
+
static void WhereAmI([CallerMemberName] string member = null)
{
Console.Out.WriteLine("Console.Out: " + member);
View
5 src/Fixie.Tests/StubListener.cs
@@ -14,6 +14,11 @@ public void AssemblyStarted(Assembly assembly)
{
}
+ public void CaseSkipped(Case @case)
+ {
+ log.Add(string.Format("{0} skipped.", @case.Name));
+ }
+
public void CasePassed(PassResult result)
{
var @case = result.Case;
View
4 src/Fixie/Conventions/Convention.cs
@@ -43,10 +43,12 @@ public void Execute(Listener listener, params Type[] candidateTypes)
var casesToExecute = casesBySkipState[false];
foreach (var @case in casesToSkip)
{
- //listener.CaseSkipped(new SkipResult(@case));
+ listener.CaseSkipped(@case);
}
var caseExecutions = casesToExecute.Select(@case => new CaseExecution(@case)).ToArray();
+ if (!caseExecutions.Any())
+ continue;
ClassExecution.Behavior.Execute(testClass, this, caseExecutions);
View
3  src/Fixie/Conventions/SelfTestConvention.cs
@@ -15,6 +15,9 @@ public SelfTestConvention()
ClassExecution
.SortCases((x, y) => String.Compare(x.Name, y.Name, StringComparison.Ordinal));
+
+ CaseExecution
+ .Skip(@case => @case.Method.Name.StartsWith("Skip"));
}
}
}
View
5 src/Fixie/Foreground.cs
@@ -22,6 +22,11 @@ public static Foreground Red
get { return new Foreground(ConsoleColor.Red); }
}
+ public static Foreground Yellow
+ {
+ get { return new Foreground(ConsoleColor.Yellow); }
+ }
+
public static Foreground DarkGray
{
get { return new Foreground(ConsoleColor.DarkGray); }
View
1  src/Fixie/Listener.cs
@@ -5,6 +5,7 @@ namespace Fixie
public interface Listener
{
void AssemblyStarted(Assembly assembly);
+ void CaseSkipped(Case @case);
void CasePassed(PassResult result);
void CaseFailed(FailResult result);
void AssemblyCompleted(Assembly assembly, AssemblyResult result);
View
6 src/Fixie/Listeners/ConsoleListener.cs
@@ -11,6 +11,12 @@ public void AssemblyStarted(Assembly assembly)
Console.WriteLine();
}
+ public void CaseSkipped(Case @case)
+ {
+ using (Foreground.Yellow)
+ Console.WriteLine("Test '{0}' skipped", @case.Name);
+ }
+
public void CasePassed(PassResult result)
{
}
View
5 src/Fixie/Listeners/TeamCityListener.cs
@@ -12,6 +12,11 @@ public void AssemblyStarted(Assembly assembly)
Message("testSuiteStarted name='{0}'", assembly.FileName());
}
+ public void CaseSkipped(Case @case)
+ {
+ Message("testIgnored name='{0}'", @case.Name);
+ }
+
public void CasePassed(PassResult result)
{
var @case = result.Case;
View
8 src/Fixie/Runner.cs
@@ -122,6 +122,7 @@ class AssemblyResultListener : Listener
{
int passed;
int failed;
+ int skipped;
readonly Listener inner;
public AssemblyResultListener(Listener inner)
@@ -133,9 +134,16 @@ public void AssemblyStarted(Assembly assembly)
{
passed = 0;
failed = 0;
+ skipped = 0;
inner.AssemblyStarted(assembly);
}
+ public void CaseSkipped(Case @case)
+ {
+ skipped++;
+ inner.CaseSkipped(@case);
+ }
+
public void CasePassed(PassResult result)
{
passed++;
Please sign in to comment.
Something went wrong with that request. Please try again.