/// <summary> /// Initializes a new instance of the <see cref="TestContext"/> class. /// </summary> /// <param name="path">The full path to the application executable.</param> /// <param name="log">The log for the test.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="path"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="path"/> is an empty string. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="log"/> is <see langword="null" />. /// </exception> public TestContext(string path, Log log) { { Lokad.Enforce.Argument(() => path); Lokad.Enforce.Argument(() => path, Lokad.Rules.StringIs.NotEmpty); Lokad.Enforce.Argument(() => log); } m_Log = log; m_Application = ApplicationProxies.StartApplication(path, log); if ((m_Application == null) || (m_Application.Process == null) || Application.Process.HasExited) { throw new RegressionTestFailedException(); } var text = string.Format( CultureInfo.InvariantCulture, "Started [{0}] - PID: [{1}]", m_Application.Name, m_Application.Process.Id); log.Info("TestContext - Create", text); }
public void Dispose() { const string prefix = "TestContext - Dispose"; try { MenuProxies.CloseApplicationViaFileExitMenuItem(m_Application, m_Log); m_Application.Process.WaitForExit(10000); } catch (Exception e) { m_Log.Error( prefix, string.Format( CultureInfo.InvariantCulture, "Failed to terminate application via the menu. Error was: {0}", e)); } try { if ((m_Application != null) && (m_Application.Process != null) && !m_Application.Process.HasExited) { ApplicationProxies.ExitApplication(m_Application, m_Log); } } catch (Exception e) { m_Log.Error( prefix, string.Format( CultureInfo.InvariantCulture, "Failed to terminate application. Error was: {0}", e)); } }
static int Main() { // Minimize directly on start-up so that we can't take focus on our own window MinimizeConsoleWindow(); var globalResult = new TestResult(); try { // Initialize the container var container = DependencyInjection.Load(); InitializeWhite(container); var reporters = container.Resolve <IEnumerable <IReporter> >(); var log = container.Resolve <Log>(); var applicationPath = ApplicationProxies.GetApolloExplorerPath(log); if (string.IsNullOrEmpty(applicationPath)) { var message = "Could not find application path."; reporters.ForEach(r => r.AddErrorMessage(message)); globalResult.AddError(message); } // Select the type of test to execute var views = container.ResolveKeyed <IUserInterfaceVerifier>(typeof(VerifyViews)); var projects = container.ResolveKeyed <IUserInterfaceVerifier>(typeof(VerifyProject)); foreach (var testCase in views.TestsToExecute().Append(projects.TestsToExecute())) { var message = string.Format( CultureInfo.InvariantCulture, "Starting: {0}", testCase.Name); reporters.ForEach(r => r.AddInformationalMessage(message)); var localResult = ExecuteTestCase(testCase, log, applicationPath); if (localResult.Status == TestStatus.Passed) { var succesMessage = string.Format( CultureInfo.InvariantCulture, "Successfully completed test: {0}", testCase.Name); reporters.ForEach(r => r.AddInformationalMessage(succesMessage)); } else { foreach (var error in localResult.Errors) { var failMessage = error; globalResult.AddError(error); reporters.ForEach(r => r.AddErrorMessage(failMessage)); } } } } catch (Exception e) { var message = string.Format( CultureInfo.InvariantCulture, "Unhandled exception occurred during the execution of the regression tests. Error was: {0}", e); globalResult.AddError(message); } return(globalResult.Status == TestStatus.Passed ? NormalApplicationExitCode : UnhandledExceptionApplicationExitCode); }