public void ExecuteForClassInitializeThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome() { // Arrange. var tai = new TestAssemblyInfo(typeof(DummyTestClass).Assembly); var constructorInfo = typeof(DummyTestClass).GetConstructors().Single(); var classAttribute = new UTF.TestClassAttribute(); var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext"); var tci = new TestClassInfo( type: typeof(DummyTestClass), constructor: constructorInfo, testContextProperty: testContextProperty, classAttribute: classAttribute, parent: tai) { ClassInitializeMethod = typeof(TestMethodRunnerTests).GetMethod( "InitMethodThrowingException", BindingFlags.Static | BindingFlags.NonPublic) }; var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, tci, this.testMethodOptions, () => { throw new Exception("DummyException"); }); var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false); // Act. var results = testMethodRunner.Execute(); // Assert. Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome); StringAssert.Contains(results[0].ErrorMessage, "System.ArgumentException: Value does not fall within the expected range."); }
public void AreEqualShouldFailWhenFloatDoubleWithMessage() { var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2, "A Message")); Assert.IsNotNull(ex); StringAssert.Contains(ex.Message, "A Message"); }
public void RunTestsForMultipleTestShouldSendMultipleResults() { var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest"); var failingTestCase = this.GetTestCase(typeof(DummyTestClass), "FailingTest"); TestCase[] tests = new[] { testCase, failingTestCase }; this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, this.cancellationToken); List <string> expectedTestCaseStartList = new List <string>() { "PassingTest", "FailingTest" }; List <string> expectedTestCaseEndList = new List <string>() { "PassingTest:Passed", "FailingTest:Failed" }; List <string> expectedResultList = new List <string>() { "PassingTest Passed", "FailingTest Failed\r\n Message: (null)" }; CollectionAssert.AreEqual(expectedTestCaseStartList, this.frameworkHandle.TestCaseStartList); CollectionAssert.AreEqual(expectedTestCaseEndList, this.frameworkHandle.TestCaseEndList); Assert.AreEqual("PassingTest Passed", this.frameworkHandle.ResultsList[0]); StringAssert.Contains( this.frameworkHandle.ResultsList[1], "FailingTest Failed\r\n Message: Assert.Fail failed. \r\n StackTrace:\r\n at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestExecutionManagerTests.DummyTestClass.FailingTest()"); }
public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() { var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(0.1M, 0.2M, "A Message")); Assert.IsNotNull(ex); StringAssert.Contains(ex.Message, "A Message"); }
public void ThrowsExceptionWithLamdaExpressionsShouldThrowAssertionOnNoException() { var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.ThrowsException <ArgumentException>(() => { })); Assert.IsNotNull(ex); Assert.AreEqual(typeof(TestFrameworkV2.AssertFailedException), ex.GetType()); StringAssert.Contains(ex.Message, "Assert.ThrowsException failed. No exception thrown. ArgumentException exception was expected."); }
public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsNull() { string warning; Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, null, out warning)); StringAssert.Contains(Resource.DeploymentItemOutputDirectoryCannotBeNull, warning); }
public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsEmpty() { string warning; Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(string.Empty, this.defaultDeploymentItemOutputDirectory, out warning)); StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning); }
public void IsFalseNullableBooleansShouldFailWithNull() { bool?nullBool = null; var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.IsFalse(nullBool)); Assert.IsNotNull(ex); StringAssert.Contains(ex.Message, "Assert.IsFalse failed"); }
public void WriteWithMessageShouldWriteToStringWriterForNullCharacters() { var stringWriter = new ThreadSafeStringWriter(null, "test"); this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties); this.testContextImplementation.Write("1 Testing \0 write \0"); StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0"); }
public void WriteShouldWriteToStringWriter() { var stringWriter = new ThreadSafeStringWriter(null, "test"); this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties); this.testContextImplementation.Write("{0} Testing write", 1); StringAssert.Contains(stringWriter.ToString(), "1 Testing write"); }
public void WriteWithMessageShouldWriteToStringWriter() { var stringWriter = new StringWriter(); this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties); this.testContextImplementation.Write("1 Testing write"); StringAssert.Contains(stringWriter.ToString(), "1 Testing write"); }
public void WriteShouldWriteToStringWriterForNullCharacters() { var stringWriter = new StringWriter(); this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties); this.testContextImplementation.Write("{0} Testing \0 write \0", 1); StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0"); }
public void RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails() { DummyTestClass.ClassCleanupMethodBody = () => UTF.Assert.Inconclusive("Test Inconclusive."); this.testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod("ClassCleanupMethod"); StringAssert.StartsWith( this.testClassInfo.RunClassCleanup(), "Class Cleanup method DummyTestClass.ClassCleanupMethod failed. Error Message: Assert.Inconclusive failed. Test Inconclusive.. Stack Trace: at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails>"); }
public void RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions() { DummyTestClass.ClassCleanupMethodBody = () => { throw new ArgumentException("Argument Exception"); }; this.testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod("ClassCleanupMethod"); StringAssert.StartsWith( this.testClassInfo.RunClassCleanup(), "Class Cleanup method DummyTestClass.ClassCleanupMethod failed. Error Message: System.ArgumentException: Argument Exception. Stack Trace: at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions>"); }
public void WriteWithMessageShouldWriteToStringWriterForReturnCharacters() { var stringWriter = new ThreadSafeStringWriter(null, "test"); this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, stringWriter, this.properties); this.testContextImplementation.Write("2 Testing write \n\r"); this.testContextImplementation.Write("3 Testing write\n\r"); StringAssert.Equals(stringWriter.ToString(), "2 Testing write 3 Testing write"); }
public void GetDiagnosticMessagesShouldReturnMessagesFromWriteLine() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties); this.testContextImplementation.WriteLine("1 Testing write"); this.testContextImplementation.WriteLine("2 Its a happy day"); StringAssert.Contains(this.testContextImplementation.GetDiagnosticMessages(), "1 Testing write"); StringAssert.Contains(this.testContextImplementation.GetDiagnosticMessages(), "2 Its a happy day"); }
public void TryGetStackTraceInformationReturnsStackTraceForAnException() { var exception = new DummyExceptionForStackTrace(() => " at A()\r\n at B()"); var stackTraceInformation = exception.TryGetStackTraceInformation(); StringAssert.StartsWith(stackTraceInformation.ErrorStackTrace, " at A()"); Assert.IsNull(stackTraceInformation.ErrorFilePath); Assert.AreEqual(0, stackTraceInformation.ErrorLineNumber); }
public void AddResultFileShouldThrowIfFileNameIsEmpty() { this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties); var exception = ActionUtility.PerformActionAndReturnException(() => this.testContextImplementation.AddResultFile(string.Empty)); Assert.AreEqual(typeof(ArgumentException), exception.GetType()); StringAssert.Contains(exception.Message, Resource.Common_CannotBeNullOrEmpty); }
public void RunTestMethodForTestThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome() { var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => { throw new Exception("Dummy Exception"); }); var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false); var results = testMethodRunner.RunTestMethod(); Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome); StringAssert.Contains(results[0].ErrorMessage, "Exception thrown while executing test"); }
public void TryGetTestFailureExceptionMessageAndStackTraceFillsInMessageAndStackTrace() { StringBuilder message = new StringBuilder(); StringBuilder stackTrace = new StringBuilder(); var testFailureException = new TestFailedException(UnitTestOutcome.NotFound, "DummyMessage", new StackTraceInformation("DummyStack")); testFailureException.TryGetTestFailureExceptionMessageAndStackTrace(message, stackTrace); StringAssert.StartsWith(message.ToString(), "DummyMessage"); StringAssert.StartsWith(stackTrace.ToString(), "DummyStack"); }
public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsRooted() { string warning; Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, "C:\\temp", out warning)); StringAssert.Contains( string.Format( Resource.DeploymentItemOutputDirectoryMustBeRelative, "C:\\temp"), warning); }
public void RunBaseClassCleanupWithNoDerivedClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions() { DummyBaseTestClass.ClassCleanupMethodBody = () => { throw new ArgumentException("Argument Exception"); }; this.testClassInfo.ClassCleanupMethod = null; this.testClassInfo.BaseClassInitAndCleanupMethods.Enqueue( Tuple.Create((MethodInfo)null, typeof(DummyBaseTestClass).GetMethod("CleanupClassMethod"))); this.testClassInfo.BaseClassCleanupMethodsStack.Push(typeof(DummyBaseTestClass).GetMethod("CleanupClassMethod")); StringAssert.StartsWith( this.testClassInfo.RunClassCleanup(), "Class Cleanup method DummyBaseTestClass.CleanupClassMethod failed. Error Message: System.ArgumentException: Argument Exception. Stack Trace: at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunBaseClassCleanupWithNoDerivedClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions>"); }
public void IsValidDeploymentItemShouldReportWarningIfOutputDirectoryHasInvalidCharacters() { string warning; Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, "<>", out warning)); StringAssert.Contains( string.Format( Resource.DeploymentItemContainsInvalidCharacters, this.defaultDeploymentItemPath, "<>"), warning); }
public void RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions() { // Arrange DummyTestClass.ClassCleanupMethodBody = () => { throw new ArgumentException("Argument Exception"); }; this.testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.ClassCleanupMethod)); // Act var classCleanup = this.testClassInfo.RunClassCleanup(); // Assert StringAssert.StartsWith(classCleanup, "Class Cleanup method DummyTestClass.ClassCleanupMethod failed."); StringAssert.Contains(classCleanup, "Error Message: System.ArgumentException: Argument Exception. Stack Trace:"); StringAssert.Contains(classCleanup, $"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions)}>"); }
public void RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive() { DummyTestClass.ClassInitializeMethodBody = (tc) => UTF.Assert.Inconclusive("Test Inconclusive"); this.testClassInfo.ClassInitializeMethod = typeof(DummyTestClass).GetMethod("ClassInitializeMethod"); var exception = ActionUtility.PerformActionAndReturnException(() => this.testClassInfo.RunClassInitialize(this.testContext)) as TestFailedException; Assert.IsNotNull(exception); Assert.AreEqual(UnitTestOutcome.Inconclusive, exception.Outcome); StringAssert.Contains(exception.Message, "Test Inconclusive"); StringAssert.StartsWith( exception.StackTraceInformation.ErrorStackTrace, " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>"); }
public void RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails() { // Arrange DummyTestClass.ClassCleanupMethodBody = () => UTF.Assert.Inconclusive("Test Inconclusive"); this.testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.ClassCleanupMethod)); // Act var classCleanup = this.testClassInfo.RunClassCleanup(); // Assert StringAssert.StartsWith(classCleanup, "Class Cleanup method DummyTestClass.ClassCleanupMethod failed."); StringAssert.Contains(classCleanup, "Error Message: Assert.Inconclusive failed. Test Inconclusive."); StringAssert.Contains(classCleanup, $"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails)}>"); }
public void RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions() { DummyTestClass.ClassInitializeMethodBody = (tc) => { throw new ArgumentException("Argument exception"); }; this.testClassInfo.ClassInitializeMethod = typeof(DummyTestClass).GetMethod("ClassInitializeMethod"); var exception = ActionUtility.PerformActionAndReturnException(() => this.testClassInfo.RunClassInitialize(this.testContext)) as TestFailedException; Assert.IsNotNull(exception); Assert.AreEqual(UnitTestOutcome.Failed, exception.Outcome); Assert.AreEqual( "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. System.ArgumentException: System.ArgumentException: Argument exception.", exception.Message); StringAssert.StartsWith( exception.StackTraceInformation.ErrorStackTrace, " at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>"); }
public void GetSettingsShouldThrowWhenParallelizeHasInvalidElements() { string runSettingxml = @"<RunSettings> <MSTestV2> <Parallelize> <Hola>Hi</Hola> </Parallelize> </MSTestV2> </RunSettings>"; var exception = ActionUtility.PerformActionAndReturnException(() => MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsNameAlias)); Assert.IsNotNull(exception); Assert.AreEqual(typeof(AdapterSettingsException).FullName, exception.GetType().FullName); StringAssert.Contains(exception.Message, "Invalid settings 'Parallelize'. Unexpected XmlElement: 'Hola'."); }
public void GetSettingsShouldThrowIfParallelizationScopeIsNotValid() { string runSettingxml = @"<RunSettings> <MSTestV2> <Parallelize> <Scope>JustParallelizeWillYou</Scope> </Parallelize> </MSTestV2> </RunSettings>"; var exception = ActionUtility.PerformActionAndReturnException(() => MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsNameAlias)); Assert.IsNotNull(exception); Assert.AreEqual(typeof(AdapterSettingsException).FullName, exception.GetType().FullName); StringAssert.Contains(exception.Message, "Invalid value 'JustParallelizeWillYou' specified for 'Scope'. Supported scopes are ClassLevel, MethodLevel."); }
public void GetSettingsShouldThrowIfParallelizationWorkersIsNegative() { string runSettingxml = @"<RunSettings> <MSTestV2> <Parallelize> <Workers>-1</Workers> </Parallelize> </MSTestV2> </RunSettings>"; var exception = ActionUtility.PerformActionAndReturnException(() => MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsNameAlias)); Assert.IsNotNull(exception); Assert.AreEqual(typeof(AdapterSettingsException).FullName, exception.GetType().FullName); StringAssert.Contains(exception.Message, "Invalid value '-1' specified for 'Workers'. The value should be a non-negative integer."); }