private string FormatReportString(string title, string message, UnitTestOutcome status,DateTime time) { return time.ToString("HH:mm:ss") + (status == UnitTestOutcome.InProgress ? "" : " " + status.ToString("G").ToUpper()) + (title.Equals(null) || title.Equals("") ? "" : " " + title) + (message.Equals(null) || message.Equals("") ? "" : "\n" + message + "\n"); }
public static void TearDown() { UnitTestOutcome outcome = context.CurrentTestOutcome; switch (outcome) { case UnitTestOutcome.Passed: /* * Do nothing when test passes */ break; default: /* * Take screenshot when test doesn't pass */ Console.WriteLine("This test failed {0}", context.TestName); //GenericHelper.TakeScreensots(); break; } Console.WriteLine("Clean up..."); if (ObjectRepository.Driver != null) { GenericHelper.HardWait(1); ObjectRepository.Driver.Quit(); ObjectRepository.Driver.Dispose(); } }
public void TestCleanUp() { TestCaseResult result = new TestCaseResult(); result.TestCaseName = this.TestContext.TestName; result.ResultDir = this.TestContext.ResultsDirectory; UnitTestOutcome executionResult = this.TestContext.CurrentTestOutcome; if (executionResult == UnitTestOutcome.Passed) { result.ExecutionResult = TestExecutionOutcome.Pass; } else { result.ExecutionResult = TestExecutionOutcome.Fail; } var currentlyRunningClassType = this.GetType().Assembly.GetTypes().FirstOrDefault(f => f.FullName == this.TestContext.FullyQualifiedTestClassName); var method = currentlyRunningClassType.GetMethod(this.TestContext.TestName); var workItemAttribute = method.GetCustomAttributes(typeof(TestCategoryAttribute)).First(); result.TestCaseCategory = ((TestCategoryAttribute)workItemAttribute).TestCategories[0]; resultSet.Add(result); }
/// <summary> /// Converts the test framework's UnitTestOutcome object to adapter's UnitTestOutcome object. /// </summary> /// <param name="frameworkTestOutcome">The test framework's UnitTestOutcome object.</param> /// <returns>The adapter's UnitTestOutcome object.</returns> public static UnitTestOutcome ToUnitTestOutcome(this UTF.UnitTestOutcome frameworkTestOutcome) { UnitTestOutcome outcome = UnitTestOutcome.Passed; switch (frameworkTestOutcome) { case UTF.UnitTestOutcome.Failed: outcome = UnitTestOutcome.Failed; break; case UTF.UnitTestOutcome.Inconclusive: outcome = UnitTestOutcome.Inconclusive; break; case UTF.UnitTestOutcome.InProgress: outcome = UnitTestOutcome.InProgress; break; case UTF.UnitTestOutcome.Passed: outcome = UnitTestOutcome.Passed; break; case UTF.UnitTestOutcome.Timeout: outcome = UnitTestOutcome.Timeout; break; case UTF.UnitTestOutcome.Unknown: default: outcome = UnitTestOutcome.Error; break; } return(outcome); }
/// <summary> /// Converts the parameter unitTestOutcome to testOutcome /// </summary> /// <param name="unitTestOutcome"> The unit Test Outcome. </param> /// <param name="mapInconclusiveToFailed">Should map inconclusive to failed.</param> /// <returns>The Test platforms outcome.</returns> internal static TestOutcome ToTestOutcome(UnitTestOutcome unitTestOutcome, bool mapInconclusiveToFailed) { switch (unitTestOutcome) { case UnitTestOutcome.Passed: return(TestOutcome.Passed); case UnitTestOutcome.Failed: case UnitTestOutcome.Error: case UnitTestOutcome.Timeout: return(TestOutcome.Failed); case UnitTestOutcome.NotRunnable: return(TestOutcome.None); case UnitTestOutcome.Ignored: return(TestOutcome.Skipped); case UnitTestOutcome.Inconclusive: { if (mapInconclusiveToFailed) { return(TestOutcome.Failed); } return(TestOutcome.Skipped); } case UnitTestOutcome.NotFound: return(TestOutcome.NotFound); default: return(TestOutcome.None); } }
public TestFailedException(UnitTestOutcome outcome, string errorMessage, StackTraceInformation stackTraceInformation, Exception realException) : base(errorMessage, realException) { Debug.Assert(!string.IsNullOrEmpty(errorMessage), "ErrorMessage should not be empty"); this.Outcome = outcome; this.StackTraceInformation = stackTraceInformation; }
static void EndTestCase(UnitTestOutcome outcome) { LogRibbon( "*", //string.Format("Test case's result was '{0}' and took {1}", outcome, StopTimingTestCase()), string.Format("Test case's result was '{0}'", outcome), string.Format("End test case '{0}' ", currentTestCaseName)); }
/// <summary> /// Log test finalization to test results file /// </summary> /// <param name="testOutput"></param> public static void Finalize(UnitTestOutcome testOutput) { if (CaseFailed || testOutput.ToString().Equals("Failed")) { ToLogFile(JPB_Framework.Report.MessageType.Empty, "Test Failed", null); } else { ToLogFile(JPB_Framework.Report.MessageType.Empty, "Test Passed", null); } WriteReportFile(); }
private string FormatReportString(string title, string message, UnitTestOutcome status, DateTime time) { var tmp = time.ToShortTimeString() + (status == UnitTestOutcome.InProgress ? "" : " " + status.ToString("G").ToUpper()) + (string.IsNullOrEmpty(title) ? "" : " " + title); var stringBulder = new StringBuilder(tmp); if (!string.IsNullOrEmpty(message)) { stringBulder.AppendLine(""); stringBulder.AppendLine(message); } return stringBulder.ToString(); }
public void TestExecution() { //Paremeters var textMessageFailed = string.Empty; var generatedEmail = Config.Credentials.Valid.Email; HomePage homePage = new HomePage(); SignInPage signInPage = new SignInPage(); SignInFormPage signInFormPage = new SignInFormPage(); AccountPage accountPage = new AccountPage(); WebDriverWait webDriverWait = new WebDriverWait(Driver.driver, TimeSpan.FromSeconds(20)); Products products = new Products(); ProductDetailsPage detailsPage = new ProductDetailsPage(); ShoppingCart shoppingCart = new ShoppingCart(); try { //Testing 'Sign Up' option SignIn.CreateAnAccount(Driver.driver, webDriverWait, homePage, signInPage, generatedEmail); SignIn.FillSignUpFormSubmit(Driver.driver, webDriverWait, signInFormPage, accountPage); //Testing 'Log In' option SignIn.LogIn(Driver.driver, webDriverWait, accountPage, homePage, signInPage, generatedEmail); //Adding products to cart using search input OrderProcess.AddBySearchInput(Driver.driver, webDriverWait, homePage, products, detailsPage); //Remove product from cart CheckoutFlow.DeleteProduct(Driver.driver, webDriverWait, homePage, shoppingCart); //Complete checkout flow CheckoutFlow.CompleteCheckout(Driver.driver, webDriverWait, shoppingCart); _testOutcome = UnitTestOutcome.Passed; } catch (Exception ex) { textMessageFailed = "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; textMessageFailed += "\nTest case failed!"; textMessageFailed += "\nError: " + ex.Message; textMessageFailed += "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; textMessageFailed += "\nException: " + ex.ToString(); ActionsPerforming.TakingScreenshotOnFailure(Driver.driver); _testOutcome = UnitTestOutcome.Failed; Assert.Fail(textMessageFailed); } }
public void TestCleanup() { sw.Stop(); string testName = string.Format("{0}.{1}", TestContext.FullyQualifiedTestClassName, TestContext.TestName); UnitTestOutcome currentTestOutcome = TestContext.CurrentTestOutcome; string message = string.Format("Test '{0}' {1} and took {2} ms", testName, currentTestOutcome.ToString().ToUpperInvariant(), sw.ElapsedMilliseconds); if (currentTestOutcome != UnitTestOutcome.Passed) { Logger.Error(message); } else { Logger.Info(message); } }
public void RepeatWithRetryTestForAllTestOutcomes( UnitTestOutcome requiredTestOutCome, int requestedRepeatCount, int requestedRetryCount, int expectedExecutionAttempts) { // Arrange TestResult[] expected = { new TestResult() { Outcome = requiredTestOutCome } }; var mockTestMethod = new Mock <ITestMethod>(); mockTestMethod.Setup(tm => tm.GetAllAttributes(false)).Returns(() => { Attribute[] attr = { new RepeatAttribute(requestedRepeatCount), new RetryAttribute(requestedRetryCount), }; return(attr); } ); var args = It.IsAny <object[]>(); mockTestMethod.Setup(tm => tm.Invoke(args)).Returns(() => { return(expected[0]); } ); // Act var retriableTestMethod = new TestMethodExAttribute(); var tr = retriableTestMethod.Execute(mockTestMethod.Object); // Assert mockTestMethod.Verify(tm => tm.Invoke(args), Times.Exactly(expectedExecutionAttempts)); Assert.AreEqual(tr.Length, expectedExecutionAttempts); Assert.IsTrue((tr.All((r) => r.Outcome == requiredTestOutCome))); }
/// <summary> /// Converts the test framework's TestResult objects array to a serializable UnitTestResult objects array. /// </summary> /// <param name="testResults">The test framework's TestResult object array.</param> /// <returns>The serializable UnitTestResult object array.</returns> public static UnitTestResult[] ToUnitTestResults(this UTF.TestResult[] testResults) { UnitTestResult[] unitTestResults = new UnitTestResult[testResults.Length]; for (int i = 0; i < testResults.Length; ++i) { UnitTestResult unitTestResult = null; UnitTestOutcome outcome = testResults[i].Outcome.ToUnitTestOutcome(); if (testResults[i].TestFailureException != null) { TestFailedException testException = testResults[i].TestFailureException as TestFailedException; unitTestResult = new UnitTestResult( new TestFailedException( outcome, testResults[i].TestFailureException.TryGetMessage(), testException != null ? testException.StackTraceInformation : testResults[i].TestFailureException.TryGetStackTraceInformation())); } else { unitTestResult = new UnitTestResult { Outcome = outcome }; } unitTestResult.StandardOut = testResults[i].LogOutput; unitTestResult.StandardError = testResults[i].LogError; unitTestResult.DebugTrace = testResults[i].DebugTrace; unitTestResult.TestContextMessages = testResults[i].TestContextMessages; unitTestResult.Duration = testResults[i].Duration; unitTestResult.DisplayName = testResults[i].DisplayName; unitTestResult.DatarowIndex = testResults[i].DatarowIndex; unitTestResult.ResultFiles = testResults[i].ResultFiles; unitTestResult.TestId = testResults[i].TestId; unitTestResult.ExecutionId = testResults[i].ExecutionId; unitTestResult.ParentExecId = testResults[i].ParentExecId; unitTestResult.InnerResultsCount = testResults[i].InnerResultsCount; unitTestResults[i] = unitTestResult; } return(unitTestResults); }
/// <summary> /// Checks whether exception is an Assert exception /// </summary> /// <param name="exception">An <see cref="Exception"/> instance.</param> /// <param name="outcome"> Adapter's Outcome depending on type of assertion.</param> /// <param name="exceptionMessage">Exception message.</param> /// <param name="exceptionStackTrace">StackTraceInformation for the exception</param> /// <returns>True, if Assert exception. False, otherwise.</returns> internal static bool TryGetUnitTestAssertException(this Exception exception, out UnitTestOutcome outcome, out string exceptionMessage, out StackTraceInformation exceptionStackTrace) { if (exception is UTF.UnitTestAssertException) { outcome = exception is UTF.AssertInconclusiveException ? UnitTestOutcome.Inconclusive : UnitTestOutcome.Failed; exceptionMessage = exception.TryGetMessage(); exceptionStackTrace = exception.TryGetStackTraceInformation(); return(true); } else { outcome = UnitTestOutcome.Failed; exceptionMessage = null; exceptionStackTrace = null; return(false); } }
/// <summary> /// Adds the test result, name, and takes and saves the screenshot if failed and sets image path /// </summary> public void AddTestCaseResult(UnitTestOutcome result, string testName) { TestName = testName; if (result == UnitTestOutcome.Inconclusive) { TestStatus = 1; Print("Interrupted *****************************************"); } else if (result == UnitTestOutcome.Passed) { TestStatus = 2; Print("PASSED *****************************************"); } else { TestStatus = 3; ImagePath = ScreenshotHandler.CaptureDesktop(testName); Print("FAILED *****************************************"); } }
private static PtfTestOutcome UnitTestOutcomeToPtfTestOutcome(UnitTestOutcome uto) { PtfTestOutcome pto = PtfTestOutcome.Unknown; switch (uto) { case UnitTestOutcome.Failed: pto = PtfTestOutcome.Failed; break; case UnitTestOutcome.Inconclusive: pto = PtfTestOutcome.Inconclusive; break; case UnitTestOutcome.Passed: pto = PtfTestOutcome.Passed; break; case UnitTestOutcome.InProgress: pto = PtfTestOutcome.InProgress; break; case UnitTestOutcome.Error: pto = PtfTestOutcome.Error; break; case UnitTestOutcome.Timeout: pto = PtfTestOutcome.Timeout; break; case UnitTestOutcome.Aborted: pto = PtfTestOutcome.Aborted; break; default: pto = PtfTestOutcome.Unknown; break; } return(pto); }
public void BugAttributeDoesNotAlterExecutionForAllTestOutcomes( UnitTestOutcome RequiredTestOutCome) { // Arrange TestResult[] expected = { new TestResult() { Outcome = RequiredTestOutCome } }; var mockTestMethod = new Mock <ITestMethod>(); mockTestMethod.Setup(tm => tm.GetAllAttributes(false)).Returns(() => { Attribute[] attr = { new BugAttribute(177) // 177 is just some int representing a bug ID }; return(attr); } ); var args = It.IsAny <object[]>(); mockTestMethod.Setup(tm => tm.Invoke(args)).Returns(() => { return(expected[0]); } ); // Act var retriableTestMethod = new TestMethodExAttribute(); var tr = retriableTestMethod.Execute(mockTestMethod.Object); // Assert mockTestMethod.Verify(tm => tm.Invoke(args), Times.Once); Assert.AreEqual(tr.Length, 1); Assert.IsTrue((tr.All((r) => r.Outcome == RequiredTestOutCome))); }
public void AddToReport(string name, string description, UnitTestOutcome status, string error) { // name, // Descritpion // Outcome - Pass/Faile // Error info - Incase of failure switch (status) { case UnitTestOutcome.Passed: extentReports.CreateTest(name, description).Pass(""); break; case UnitTestOutcome.Failed: extentReports.CreateTest(name, description).Fail(error); break; default: extentReports.CreateTest(name, description).Skip(""); break; } }
public void StopRecording(UnitTestOutcome TestOutcome) { stopped = true; recordingTask.Wait(); if (TestOutcome == UnitTestOutcome.Passed) { File.Delete(filename); } else { string TestResultsRootPath = Directory.GetParent(Directory.GetParent(Directory.GetParent(filename).ToString()).ToString()).ToString(); string destFileName = Path.Combine(TestResultsRootPath, Path.GetFileName(filename)); if (File.Exists(filename)) { if (File.Exists(destFileName)) { File.Delete(destFileName); } File.Move(filename, destFileName); } } }
/// <summary> /// Initialize a new instance of <see cref="ReadonlyTestCase"/> to report a non-success outcome. /// </summary> /// <param name="outcome"></param> /// <param name="notSuccessTitle">The name that will be displayed when the test case.</param> /// <param name="notSuccessReason">The reason why this test case is not runnable.</param> internal ReadonlyTestCase(UnitTestOutcome outcome, [NotNull] string notSuccessTitle, [NotNull] string notSuccessReason) { if (outcome == UnitTestOutcome.Passed) { throw new ArgumentException("This constructor only support non-success outcome.", nameof(outcome)); } if (notSuccessReason == null) { throw new ArgumentNullException(nameof(notSuccessReason)); } DisplayName = notSuccessTitle ?? throw new ArgumentNullException(nameof(notSuccessTitle)); Contract.EndContractBlock(); Result = new TestResult { Outcome = outcome, DisplayName = notSuccessTitle, TestContextMessages = notSuccessReason, }; }
public override void Report(string title, string message, bool bold, UnitTestOutcome status, DateTime time) { const string timeStampclassName = "time_stamp"; _currentHtmlTest.AddAttribute(HtmlTextWriterAttribute.Class, timeStampclassName); _currentHtmlTest.RenderBeginTag(HtmlTextWriterTag.Div); _currentHtmlTest.Write(time); _currentHtmlTest.RenderEndTag(); // add a new report to the test // <div class="timestamp">time</div> // <div class="report_status_fail/worning/pass"> _currentHtmlTest.AddAttribute(HtmlTextWriterAttribute.Class, status.ToString().ToLower()); _currentHtmlTest.RenderBeginTag(HtmlTextWriterTag.Div); const string testReportClassName = "test_report"; _currentHtmlTest.AddAttribute(HtmlTextWriterAttribute.Class, testReportClassName); _currentHtmlTest.Write(message); _currentHtmlTest.RenderEndTag(); // <div class="test_report"><b>message</b></div> // </div> }
private void UnitTest_UnitTestCompletedEvent(object sender, UnitTestOutcome outcome) { UnitTest test = sender as UnitTest; string result = string.Empty; string additionaldata = string.Empty; switch (outcome.Result) { case UnitTestResult.Passed: Console.ForegroundColor = ConsoleColor.Green; break; case UnitTestResult.Inconclusive: Console.ForegroundColor = ConsoleColor.Yellow; break; case UnitTestResult.Failed: Console.ForegroundColor = ConsoleColor.Yellow; break; case UnitTestResult.Error: Console.ForegroundColor = ConsoleColor.Red; break; } if (!string.IsNullOrWhiteSpace(outcome.Description)) { Console.WriteLine("{0} ", outcome.Result.ToString()); Console.ResetColor(); Console.WriteLine(); Console.WriteLine(outcome.Description); } else { Console.WriteLine("{0}", outcome.Result.ToString()); } Console.ResetColor(); }
public override void Report(string title, string message, bool bold, UnitTestOutcome status, DateTime time) { Write(FormatReportString(title, message, status,time)); }
public override void Report(string title, string message, bool bold, UnitTestOutcome status, DateTime time) { if (status.Equals(UnitTestOutcome.Failed) || status.Equals(UnitTestOutcome.Error)) _saveTestStatusIfFailed = status; foreach (var listener in listeners) { if (listener is IReporter) { ((IReporter) listener).Report(title, message, bold, status, time); } } }
public TestFailedException(UnitTestOutcome outcome, string errorMessage, Exception realException) : this(outcome, errorMessage, null, realException) { }
public void Report(string title, UnitTestOutcome status) { Report(title, "",status); }
public void RecordEnd(UnitTestElement test, UnitTestOutcome outcome) { this.recorder.RecordEnd(test.ToTestCase(), UnitTestOutcomeHelper.ToTestOutcome(outcome, MSTestSettings.CurrentSettings)); }
public void Report(string title, string message, UnitTestOutcome status) { Report(title, message, false, status); }
public void StartTest(TestContext testContext) { _saveTestStatusIfFailed = UnitTestOutcome.Passed; foreach (var listener in listeners.OfType<ITestListener>()) { (listener).StartTest(testContext); } }
public override int GetTestOutcomeCount(UnitTestOutcome outcome) { return base.GetTestOutcomeCount(outcome) + (TestInitializeMethod != null && TestInitializeMethod.Outcome == outcome ? 1 : 0) + (TestCleanupMethod != null && TestCleanupMethod.Outcome == outcome ? 1 : 0); }
public TestFailedException(UnitTestOutcome outcome, string errorMessage, StackTraceInformation stackTraceInformation) : this(outcome, errorMessage, stackTraceInformation, null) { }
private static int NumberOf(this IComposedUnitTestOutcome outcome, UnitTestOutcome toFind) { return outcome.TestResults.Where(p => p.Result == toFind).Count(); }
public virtual int GetTestOutcomeCount(UnitTestOutcome outcome) { return (Outcome == outcome ? 1 : 0); }
/// <summary> /// Log test finalization to test results file /// </summary> /// <param name="testClassName"></param> /// <param name="testMethodName"></param> /// <param name="testOutput"></param> public static void Finalize(UnitTestOutcome testOutput) { ToLogFile(JPB_Framework.Report.MessageType.Empty, $"Test {testOutput}", null); WriteReportFile(); }
/// <summary> /// Initializes a new instance of the <see cref="UnitTestResult"/> class. /// </summary> /// <param name="outcome"> The outcome. </param> /// <param name="errorMessage"> The error message. </param> internal UnitTestResult(UnitTestOutcome outcome, string errorMessage) : this() { this.Outcome = outcome; this.ErrorMessage = errorMessage; }
public void Report(string title, string message, bool bold, UnitTestOutcome status) { Report(title, message, false, status, DateTime.Now); }
/// <summary> /// Converts the test framework's TestResult objects array to a serializable UnitTestResult objects array. /// </summary> /// <param name="testResults">The test framework's TestResult object array.</param> /// <returns>The serializable UnitTestResult object array.</returns> public static UnitTestResult[] ToUnitTestResults(this UTF.TestResult[] testResults) { UnitTestResult[] unitTestResults = new UnitTestResult[testResults.Length]; for (int i = 0; i < testResults.Length; ++i) { UnitTestResult unitTestResult = null; UnitTestOutcome outcome = UnitTestOutcome.Passed; switch (testResults[i].Outcome) { case UTF.UnitTestOutcome.Failed: outcome = UnitTestOutcome.Failed; break; case UTF.UnitTestOutcome.Inconclusive: outcome = UnitTestOutcome.Inconclusive; break; case UTF.UnitTestOutcome.InProgress: outcome = UnitTestOutcome.InProgress; break; case UTF.UnitTestOutcome.Passed: outcome = UnitTestOutcome.Passed; break; case UTF.UnitTestOutcome.Timeout: outcome = UnitTestOutcome.Timeout; break; case UTF.UnitTestOutcome.Unknown: default: outcome = UnitTestOutcome.Error; break; } if (testResults[i].TestFailureException != null) { TestFailedException testException = testResults[i].TestFailureException as TestFailedException; unitTestResult = new UnitTestResult( new TestFailedException( outcome, testResults[i].TestFailureException.TryGetMessage(), testException != null ? testException.StackTraceInformation : testResults[i].TestFailureException.TryGetStackTraceInformation())); } else { unitTestResult = new UnitTestResult { Outcome = outcome }; } unitTestResult.StandardOut = testResults[i].LogOutput; unitTestResult.StandardError = testResults[i].LogError; unitTestResult.DebugTrace = testResults[i].DebugTrace; unitTestResult.TestContextMessages = testResults[i].TestContextMessages; unitTestResult.Duration = testResults[i].Duration; unitTestResult.DisplayName = testResults[i].DisplayName; unitTestResult.DatarowIndex = testResults[i].DatarowIndex; unitTestResult.ResultFiles = testResults[i].ResultFiles; unitTestResults[i] = unitTestResult; } return(unitTestResults); }
public static void Cleanup(UnitTestOutcome outcome) { EndTestCase(outcome); //StopTimingTestCase(); //OutputTestCaseTimes(); }
private static PtfTestOutcome UnitTestOutcomeToPtfTestOutcome(UnitTestOutcome uto) { PtfTestOutcome pto = PtfTestOutcome.Unknown; switch (uto) { case UnitTestOutcome.Failed: pto = PtfTestOutcome.Failed; break; case UnitTestOutcome.Inconclusive: pto = PtfTestOutcome.Inconclusive; break; case UnitTestOutcome.Passed: pto = PtfTestOutcome.Passed; break; case UnitTestOutcome.InProgress: pto = PtfTestOutcome.InProgress; break; case UnitTestOutcome.Error: pto = PtfTestOutcome.Error; break; case UnitTestOutcome.Timeout: pto = PtfTestOutcome.Timeout; break; case UnitTestOutcome.Aborted: pto = PtfTestOutcome.Aborted; break; default: pto = PtfTestOutcome.Unknown; break; } return pto; }
public abstract void Report(string title, string message, bool bold, UnitTestOutcome status, DateTime time);