public void ExecuteWithNullMethodsRunAllTestMethods() { StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(VarietyTestClass.TestMethodCount, result.Results.Count); }
protected IEnumerable <MethodResult> RunClass(Type typeUnderTest) { ITestClassCommand testClassCommand = new TestClassCommand(typeUnderTest); ClassResult classResult = TestClassCommandRunner.Execute(testClassCommand, testClassCommand.EnumerateTestMethods().ToList(), startCallback: null, resultCallback: null); return(classResult.Results.OfType <MethodResult>()); }
public void CannotUseTestClassAsItsOwnFixture() { TestClassCommand command = new TestClassCommand(typeof(InvalidTestClassWithSelfFixture)); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(typeof(InvalidOperationException).FullName, result.ExceptionType); Assert.Equal(0, result.Results.Count); }
public void FixtureDataDisposeFailure_InvocationException() { TestClassCommand command = new TestClassCommand(typeof(DataDisposeFailureSpy)); DataDisposeThrow.Exception = new TargetInvocationException(new Exception()); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal("System.Reflection.TargetInvocationException", result.ExceptionType); }
public void ClassResultContainsOneResultForEachTestMethod() { TestClassCommand command = new TestClassCommand(); command.TypeUnderTest = Reflector.Wrap(typeof(Spy)); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(3, result.Results.Count); }
public void ClassFinishException() { StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); command.ClassFinish__Result = new Exception(); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(typeof(Exception) + " : " + command.ClassFinish__Result.Message, result.Message); Assert.Equal(command.ClassFinish__Result.StackTrace, result.StackTrace); }
public void RandomizerUsedToDetermineTestOrder() { RandomSpy randomizer = new RandomSpy(); TestClassCommand command = new TestClassCommand(typeof(OrderingSpy)); command.Randomizer = randomizer; TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(OrderingSpy.TestMethodCount, randomizer.Next__Count); }
public void TestsCanBePrivateMethods() { TestClassCommand command = new TestClassCommand(); command.TypeUnderTest = Reflector.Wrap(typeof(PrivateSpy)); PrivateSpy.Reset(); TestClassCommandRunner.Execute(command, null, null, null); Assert.True(PrivateSpy.WasRun); }
public void ExecuteWithSpecificMethodOnlyRunsThatMethod() { StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); List <IMethodInfo> methods = new List <IMethodInfo> { Reflector.Wrap(typeof(VarietyTestClass).GetMethod("PassedTest")) }; ClassResult result = TestClassCommandRunner.Execute(command, methods, null, null); Assert.Single(result.Results); }
public void ExecuteWillNotRunRequestedNonTestMethod() { StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); List <IMethodInfo> methods = new List <IMethodInfo> { Reflector.Wrap(typeof(VarietyTestClass).GetMethod("NonTestMethod")) }; ClassResult result = TestClassCommandRunner.Execute(command, methods, null, null); Assert.Equal(0, result.Results.Count); }
public void FixtureDataConstructorFailure_InvocationException() { TestClassCommand command = new TestClassCommand(); command.TypeUnderTest = Reflector.Wrap(typeof(DataCtorFailureSpy)); DataCtorThrow.Exception = new TargetInvocationException(new Exception()); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal("System.Reflection.TargetInvocationException", result.ExceptionType); }
public static IEnumerable <MethodResult> Run(Type featureDefinition) { var feature = new TestClassCommand(featureDefinition); MethodResult[] results = null; var thread = new Thread(() => results = TestClassCommandRunner.Execute(feature, feature.EnumerateTestMethods().ToList(), startCallback: null, resultCallback: null).Results .OfType <MethodResult>().ToArray()); thread.Start(); thread.Join(); return(results); }
public void ClassStartExceptionDoesNotRunTestsButDoesCallClassFinish() { StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); command.ClassStart__Result = new Exception(); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.True(command.ClassStart__Called); Assert.True(command.ClassFinish__Called); Assert.Equal(typeof(Exception) + " : " + command.ClassStart__Result.Message, result.Message); Assert.Equal(command.ClassStart__Result.StackTrace, result.StackTrace); Assert.Equal(0, result.Results.Count); }
public void CtorFailure() { TestClassCommand command = new TestClassCommand(); command.TypeUnderTest = Reflector.Wrap(typeof(CtorFailureSpy)); CtorFailureSpy.Reset(); CtorFailureSpy.dummyTestCalled = 0; TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(1, CtorFailureSpy.dataCtorCalled); Assert.Equal(1, CtorFailureSpy.ctorCalled); Assert.Equal(0, CtorFailureSpy.dummyTestCalled); Assert.Equal(0, CtorFailureSpy.disposeCalled); Assert.Equal(1, CtorFailureSpy.dataDisposeCalled); }
public void UsesProvidedObjectInstanceForAllTests() { InstanceSpy originalObject = new InstanceSpy(); StubTestClassCommand command = new StubTestClassCommand(typeof(InstanceSpy)); command.ObjectUnderTest__Result = originalObject; InstanceSpy.Reset(); TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(3, InstanceSpy.instances.Count); foreach (object obj in InstanceSpy.instances) { Assert.Same(originalObject, obj); } }
public void ResultCallbackIsCalledWithCorrectResults() { int classCounter = 0; int errorCounter = 0; int failedCounter = 0; int passedCounter = 0; int skippedCounter = 0; StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); TestClassCommandRunner.Execute( command, null, null, result => { if (result is PassedResult) { passedCounter++; } else if (result is FailedResult) { failedCounter++; } else if (result is SkipResult) { skippedCounter++; } else if (result is ClassResult) { classCounter++; } else { errorCounter++; } return(true); } ); Assert.Equal(1, passedCounter); Assert.Equal(1, failedCounter); Assert.Equal(1, skippedCounter); Assert.Equal(1, classCounter); Assert.Equal(0, errorCounter); }
public void DisposeFailure() { TestClassCommand command = new TestClassCommand(); command.TypeUnderTest = Reflector.Wrap(typeof(DisposeFailureSpy)); DisposeFailureSpy.Reset(); DisposeFailureSpy.dummyTestCalled = 0; TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(1, DisposeFailureSpy.dataCtorCalled); Assert.Equal(1, DisposeFailureSpy.ctorCalled); Assert.Equal(1, DisposeFailureSpy.dummyTestCalled); Assert.Equal(1, DisposeFailureSpy.disposeCalled); Assert.Equal(1, DisposeFailureSpy.dataDisposeCalled); Assert.Equal("ctorData ctor setFixture dispose disposeData ", DisposeFailureSpy.callOrder); }
public IMessageSinkMessage[] Run(Type feature) { var command = new TestClassCommand(feature); IMessageSinkMessage[] results = null; var thread = new Thread(() => results = TestClassCommandRunner .Execute(command, command.EnumerateTestMethods().ToList(), null, null) .Results .Select(Map) .Where(message => message != null) .ToArray()); thread.Start(); thread.Join(); return(results); }
public XmlNode RunTests(string type, List <string> methods, Predicate <XmlNode> callback) { var testClass = testRun.Classes.Single(c => c.Typename == type); var methodInfos = (from m in methods select testClass.GetMethod(m)).ToList(); Predicate <XmlNode> nonNullCallback = node => node == null || callback(node); var testClassCommand = TestClassCommandFactory.Make(testClass); SetRandomizer(testClassCommand); var classResult = TestClassCommandRunner.Execute(testClassCommand, methodInfos, command => nonNullCallback(command.ToStartXml()), result => nonNullCallback(ToXml(resultInspector(result)))); return(ToXml(classResult)); }
public void FixtureDataDisposeFailure() { TestClassCommand command = new TestClassCommand(typeof(DataDisposeFailureSpy)); DataDisposeFailureSpy.Reset(); DataDisposeFailureSpy.dummyTestCalled = 0; DataDisposeThrow.Exception = new Exception(); ClassResult result = TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(1, DataDisposeFailureSpy.dataCtorCalled); Assert.Equal(1, DataDisposeFailureSpy.ctorCalled); Assert.Equal(1, DataDisposeFailureSpy.dummyTestCalled); Assert.Equal(1, DataDisposeFailureSpy.disposeCalled); Assert.Equal(1, DataDisposeFailureSpy.dataDisposeCalled); Assert.Equal("ctorData ctor setFixture dispose disposeData ", DataDisposeFailureSpy.callOrder); Assert.NotNull(result.Message); Assert.Equal("System.Exception", result.ExceptionType); }
public void StartCallbackIsCalled() { int count = 0; string passName = typeof(VarietyTestClass).FullName + ".PassedTest"; string failName = typeof(VarietyTestClass).FullName + ".FailedTest"; string skipName = typeof(VarietyTestClass).FullName + ".SkippedTest"; bool foundPass = false; bool foundFail = false; bool foundSkip = false; StubTestClassCommand command = new StubTestClassCommand(typeof(VarietyTestClass)); TestClassCommandRunner.Execute( command, null, cmd => { ++count; if (cmd.DisplayName == passName) { foundPass = true; } if (cmd.DisplayName == failName) { foundFail = true; } if (cmd.DisplayName == skipName) { foundSkip = true; } return(true); }, null ); Assert.Equal(3, count); Assert.True(foundPass); Assert.True(foundFail); Assert.True(foundSkip); }
public void AllStagesOfTestLifetimeExistOnSameThread() { Type testClassType = typeof(ThreadLifetimeSpy); ITestClassCommand command = TestClassCommandFactory.Make(testClassType); ThreadFixtureSpy.Reset(); ThreadLifetimeSpy.Reset(); TestClassCommandRunner.Execute(command, null, null, null); // The fixture data may take place on a different thread from the test, but that's // an acceptable limitation, as the fixture should have no knowledge of the test // class that it's attached to. This means that fixtures cannot use thread local // storage, but there's no reason for them to need that anyway, as their own data // remains the same throughout all the tests for a given class. Assert.NotEqual(-1, ThreadFixtureSpy.CtorThreadId); Assert.Equal(ThreadFixtureSpy.CtorThreadId, ThreadFixtureSpy.DisposeThreadId); Assert.NotEqual(-1, ThreadLifetimeSpy.CtorThreadId); Assert.Equal(ThreadLifetimeSpy.CtorThreadId, ThreadLifetimeSpy.DisposeThreadId); Assert.Equal(ThreadLifetimeSpy.CtorThreadId, ThreadLifetimeSpy.TestThreadId); }
public void TestMethodCounters() { TestClassCommand command = new TestClassCommand(); command.TypeUnderTest = Reflector.Wrap(typeof(InstrumentedTestClass)); InstrumentedTestClass.Reset(); InstrumentedTestClass.passedTestCalled = 0; InstrumentedTestClass.failedTestCalled = 0; InstrumentedTestClass.skipTestCalled = 0; InstrumentedTestClass.nonTestCalled = 0; TestClassCommandRunner.Execute(command, null, null, null); Assert.Equal(1, InstrumentedTestClass.dataCtorCalled); Assert.Equal(2, InstrumentedTestClass.ctorCalled); // Two non-skipped tests, the skipped test does not create an instance Assert.Equal(1, InstrumentedTestClass.passedTestCalled); Assert.Equal(1, InstrumentedTestClass.failedTestCalled); Assert.Equal(0, InstrumentedTestClass.skipTestCalled); Assert.Equal(0, InstrumentedTestClass.nonTestCalled); Assert.Equal(2, InstrumentedTestClass.disposeCalled); Assert.Equal(1, InstrumentedTestClass.dataDisposeCalled); Assert.Equal("ctorData ctor setFixture dispose ctor setFixture dispose disposeData ", InstrumentedTestClass.callOrder); }
public void TimeoutCommandMustUseReplacementBeginInvoke() { Type testClassType = typeof(TestClassCommandFactoryTests.ThreadLifetimeSpy); ITestClassCommand command = TestClassCommandFactory.Make(testClassType); TestClassCommandFactoryTests.ThreadFixtureSpy.Reset(); TestClassCommandFactoryTests.ThreadLifetimeSpy.Reset(); try { TestClassCommandRunner.Execute(command, null, null, null); } catch (NotSupportedException e) { // If this test fails, you need to modify TimeoutCommand.Execute to use // working versions of delegate's BeginInvoke/EndInvoke. You should replace // with WorkingBeginInvoke and WorkingEndInvoke. WorkingEndInvoke's return // value will require casting to MethodResult. // The asynchronous methods on Invoke are compiler generated, and supposed // to be implemented by the runtime. Silverlight doesn't implement them. // I don't really know why. throw new AsyncDelegateMethodsNotSupportedException("TimeoutCommand.Execute", e); } }