void SetStartUpParameters(ITestRun testRun) { if (TestRunStartTypes.Immediately == testRun.StartType) testRun.Status = TestRunQueue.TestRuns.Any(tr => tr.TestLabId == testRun.TestLabId && tr.IsQueued()) ? TestRunStatuses.Pending : TestRunStatuses.Running; if (testRun.IsActive()) testRun.SetStartTime(); }
public void SetUp() { TestSettings.PrepareModuleTests(); TestFactory.GetTestRunWithStatus(TestRunStatuses.Running); _workflow = WorkflowCollection.Workflows.First(); _testRun = TestRunQueue.TestRuns.First(); }
void SetCommonData(ITestRun testRun, IDictionary<string, object> formData) { if (null == formData || 0 >= formData.Count) return; foreach (var pair in formData) AddOrUpdateDataItem(testRun, formData, pair.Key); }
void AddOrUpdateDataItem(ITestRun testRun, IDictionary<string, object> formData, string key) { testRun.Data.AddOrUpdateDataItem( new CommonDataItem { Key = key, Value = (formData[key] ?? string.Empty).ToString() }); }
public void CancelTestRun(ITestRun testRun) { TaskPool.TasksForClients.Where(task => task.TestRunId == testRun.Id && !task.IsFinished() && !task.IsActive()).ToList().ForEach(task => task.TaskStatus = TestTaskStatuses.Canceled); testRun.Status = TestRunStatuses.Cancelled; if (TaskPool.TasksForClients.Any(task => task.TestRunId == testRun.Id && task.IsActive())) { TaskPool.TasksForClients.Where(task => task.TestRunId == testRun.Id && task.IsActive()).ToList().ForEach(task => task.TaskStatus = TestTaskStatuses.Interrupted); testRun.Status = TestRunStatuses.Cancelling; } // disconnecting clients ClientsCollection.Clients.RemoveAll(client => client.TestRunId == testRun.Id); testRun.SetTimeTaken(); RunNextInRowTestRun(); }
public static TestResult Map(ITestRun testRun, double? coverage, string serverName) { return new TestResult() { ServerName = serverName, CompletedTime = testRun.DateCompleted, PassedTestCount = testRun.Statistics.PassedTests, FailedTestCount = testRun.Statistics.FailedTests, NotRunTestCount = testRun.Statistics.InconclusiveTests, TotalTestCount = testRun.Statistics.TotalTests, CodeCoverage = coverage != null ? new CodeCoverageResult() { CompletedTime = testRun.DateCompleted, Coverage = coverage.Value } : null }; }
public virtual void CancelTestRun(ITestRun testRun) { TaskPool.TasksForClients.Where(task => task.TestRunId == testRun.Id && !task.IsFinished() && !task.IsActive() && !task.IsCancel).ToList().ForEach(task => task.TaskStatus = TestTaskStatuses.Canceled); var activeTasks = TaskPool.TasksForClients.Where(task => task.TestRunId == testRun.Id && task.IsActive()).ToList(); if (activeTasks.Any()) { // 20150918 // temporarily // until there'll be async execution of task here // linked lines of code 20150918-001 // activeTasks.ForEach(task => { if (!task.IsCancel) task.TaskStatus = TestTaskStatuses.InterruptedByUser; }); // TODO: provide all clients that ran active tasks with newly available tasks // however clients can't interrupt their tasks // testRun.Status = TestRunStatuses.Canceling; } else { testRun.Status = TestRunStatuses.Canceled; } // TODO: set test run status Canceled after all isCancel tasks have finished // disconnecting clients // 20150807 // ClientsCollection.Clients.RemoveAll(client => client.TestRunId == testRun.Id); // 20150909 // no more unregistration of clients // testRun.UnregisterClients(); // set time only for completely cancelled test runs // testRun.SetTimeTaken(); if (TestRunStatuses.Canceled == testRun.Status) testRun.SetTimeTaken(); // 20150909 // RunNextInRowTestRun(); if (TestRunStatuses.Canceled == testRun.Status) RunNextInRowTestRun(); }
void ThenTestRunIsRunning(ITestRun testRun) { Assert.Equal(true, testRun.IsActive()); }
void ThenTestRunIsCompleted(ITestRun testRun) { Assert.Equal(true, testRun.IsCompleted()); }
public static string GetFileName(this ITestRun testRun) { return(testRun.TestInfo.Finish.GetTestName()); }
public static bool IsActive(this ITestRun testRun) { // 20150918 // return TestRunStatuses.Running == testRun.Status; return(TestRunStatuses.Running == testRun.Status || TestRunStatuses.Canceling == testRun.Status); }
public static string GetTestLabName(this ITestRun testRun) { return(TestLabCollection.TestLabs.FirstOrDefault(testLab => testLab.Id == testRun.TestLabId).Name); }
public static void SetStartTime(this ITestRun testRun) { testRun.StartTime = DateTime.Now; }
public static void SetTimeTaken(this ITestRun testRun) { (testRun as TestRun).SetFinishTime(); }
public static bool IsScheduled(this ITestRun testRun) { return(TestRunStatuses.Scheduled == testRun.Status); }
public static bool IsQueued(this ITestRun testRun) { return(TestRunStatuses.Running == testRun.Status || TestRunStatuses.Pending == testRun.Status); }
public static bool IsPending(this ITestRun testRun) { return(TestRunStatuses.Pending == testRun.Status); }
public static bool IsNotQuiet(this ITestRun testRun) { return(TestRunStatuses.Running == testRun.Status || TestRunStatuses.Canceling == testRun.Status); }
public static bool IsAcceptingNewClients(this ITestRun testRun) { return(TestRunStatuses.Running == testRun.Status); }
/// <summary> /// Executes a test run. The ITestRun object specifies which tests to run /// and how. If the tests write to the console (either Error or Out) this /// output will be redirected to 'twConsole'. /// </summary> /// <param name="testRun">ITestRun object describing what tests to run and how.</param> /// <param name="twConsole">TextWriter to where Out and Error are redirected.</param> public void RunTests(ITestRun testRun, TextWriter twConsole) { SetUpConsoleAndWorkingDirectory(twConsole); if( _listener != null ) { _listener.OnAssemblyStarted(null, new AssemblyEventArgs(_testAssembly.FullName, _testAssembly.CodeBase)); } try { _testAssembly.RunTests(testRun, _listener); } catch( Exception ex ) { if( _listener != null ) { _listener.OnTestsAborted(null, new AssemblyEventArgs(_testAssembly.FullName, _testAssembly.CodeBase)); } CheckAndHandleCsUnitCrash(ex); } finally { if( _listener != null ) { _listener.OnAssemblyFinished(null, new AssemblyEventArgs(_testAssembly.FullName, _testAssembly.CodeBase)); } RestoreConsoleAndWorkingDirectory(); } }
public void RunTests(ITestRun testSelection) { RaiseAbortedEvent(); }
void WhenCancelingTestRun(ITestRun testRun) { _response = _browser.Put(UrlList.TestRuns_Root + "/" + testRun.Id + "/cancelTestRun", with => { with.Accept("application/json"); }); }
public void RunTests(ITestRun testSelection) { RaiseAbortedEvent(); }
void THEN_testRun_is_completed(ITestRun testRun) { Assert.Equal(true, testRun.IsCompleted()); }
/// <summary> /// Executes tests specified as a test run. The TestRun object contains /// information about what tests to execute and how. /// </summary> /// <param name="testRun">Information about the test run.</param> public void RunTests(ITestRun testRun) { if (_testAssemblies.Count > 0) { _testRun = testRun; PrepareTestRun(); RunTests(_queuedAssemblies.Dequeue(), _testRun); } }
void ThenTestRunIsPending(ITestRun testRun) { Assert.Equal(true, testRun.IsPending()); }
private void RunTests(ITestAssembly testAssembly, ITestRun testRun) { if( testAssembly != null ) { try { //testAssembly.Refresh(); testAssembly.RunTests(testRun); } catch( Exception ex ) { // Invoke the abort event b/c an exception that goes unhandled // here is the equivalent of an aborted recipe. var recipeEventArgs = new RecipeEventArgs(ex.Message); TestsRunning = false; if( Aborted != null ) { Aborted(this, recipeEventArgs); } } } }
void ThenTestRunStatusIsCanceled(ITestRun testRun) { Assert.Equal(TestRunStatuses.Canceled, testRun.Status); }
public void RunTests(ITestRun testRun) { throw new Exception("The method or operation is not implemented."); }
void WhenCancelingTestRun(ITestRun testRun) { _response = _browser.Put(UrlList.TestRuns_Root + "/" + testRun.Id + "/cancelTestRun", with => { with.Accept("application/json"); }); }
/// <summary> /// This method is used to initiate execution in test manager, create test run and results and set required parameters /// </summary> /// <returns></returns> public bool InitExecution() { //Create a connection to tfs project ITestManagementTeamProject tfsProject = null; tfsProject = GetProject(ProjectUrl, ProjectName); if (tfsProject == null) { throw new Exception("Unabled to connect to test project: " + ProjectName); } //Retrieve test plan details ITestPlanCollection testPlans = tfsProject.TestPlans.Query("select * from TestPlan where PlanName ='" + TestPlanName + "'"); if (testPlans.Count == 0) { throw new Exception("Unabled to locate test plan: " + TestPlanName + " in Test Manager."); } ITestPlan tfsTestPlan = testPlans.First(); //Retrieve test suite details ITestSuiteCollection testSuites = null; //Optionally, test suite id of test manager can be passed as an command line arguments //This helps when same test case has been added to multiple test suites if (TestSuiteId.ToLower().Equals(string.Empty) || TestSuiteId.ToLower().Equals(string.Empty) || TestSuiteId.ToLower().Equals("testsuiteid", StringComparison.OrdinalIgnoreCase)) { testSuites = tfsProject.TestSuites.Query("Select * from TestSuite where Title='" + TestSuiteName + "' and PlanID='" + tfsTestPlan.Id + "'"); } else { testSuites = tfsProject.TestSuites.Query("Select * from TestSuite where Id='" + TestSuiteId + "' and PlanID='" + tfsTestPlan.Id + "'"); } IStaticTestSuite tfsTestSuite = testSuites.Cast <IStaticTestSuite>().FirstOrDefault(testSuite => testSuite.Title.ToLower().Equals(TestSuiteName.ToLower()) || testSuite.Id.ToString().Equals(TestSuiteId)); if (tfsTestSuite == null) { throw new Exception("Unabled to locate test suite: " + TestSuiteName + " in Test Manager Test Plan: " + TestPlanName); } //Get handle to a specific test case in the test suite ITestCase tfsTestCase = tfsTestSuite.AllTestCases.FirstOrDefault(testcase => testcase.Id.Equals(TestCaseId)); if (tfsTestCase == null) { throw new Exception("Unabled to locate test case id: " + TestCaseId + " in Test Manager"); } //Create a test run ITestPoint tfsTestPoint = CreateTestPoints(tfsTestPlan, tfsTestSuite, tfsTestCase); ITestRun tfsTestRun = CreateTestRun(tfsProject, tfsTestPlan, tfsTestPoint); tfsTestRun.Refresh(); //Suprisingly, most recently created test results should be available in last, but test manager returns it at first position //Find test results that were create by the test run ITestCaseResultCollection tfsTestCaseResults = tfsProject.TestResults.ByTestId(tfsTestCase.Id); ITestCaseResult tfsTestResult = tfsTestCaseResults.Last(); //Default assignment foreach (ITestCaseResult testResult in tfsTestCaseResults) { if (testResult.DateCreated.CompareTo(tfsTestRun.DateCreated) == 1) { tfsTestResult = testResult; break; } } //Set test run and result id to property variable for usage while uploading results Property.RcTestRunId = tfsTestRun.Id; Property.RcTestResultId = tfsTestResult.TestResultId; //Set status of test case execution //Set other details on test execution tfsTestResult.ComputerName = Property.RcMachineId; tfsTestResult.DateStarted = DateTime.Now; tfsTestResult.State = TestResultState.InProgress; tfsTestResult.Save(); return(true); }
private void AddTestResultByTestoutcome(ITestRun testRun, IList<TestOutcome> outcomeList, ref IList<TestResult> list) { foreach (var outcome in outcomeList) { foreach (var tr in testRun.QueryResultsByOutcome(outcome)) { TestResult instance = new TestResult { TestCaseId = tr.TestCaseId, TestCaseTitle = tr.TestCaseTitle, State = tr.State, Outcome = tr.Outcome, DateStarted = tr.DateStarted, DateCompleted = tr.DateCompleted, ErrorMsg = tr.ErrorMessage, LogUri = tr.Attachments.FirstOrDefault().Uri.AbsoluteUri, }; list.Add(instance); } } }
void ThenTestRunIsPending(ITestRun testRun) { Assert.Equal(true, testRun.IsPending()); }
string GIVEN_url_to_testRun_data() { _testRun = new TestRun(); ClientSettings.Instance.CurrentClient = new TestClient { TestRunId = _testRun.Id }; return UrlList.TestData_Root + "/" + _testRun.Id + UrlList.TestData_CommonData_forClient_relPath; }
void ThenTestRunStatusIsCanceled(ITestRun testRun) { Assert.Equal(TestRunStatuses.Canceled, testRun.Status); }
public void RunTests(ITestRun selection) { if( Started != null ) { Started(this, new RecipeEventArgs()); } }
public static void UnregisterClients(this ITestRun testRun) { // TODO: send command to unregister to clients ClientsCollection.Clients.RemoveAll(client => client.TestRunId == testRun.Id); }
// [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_one_task_to_the_common_pool_on_imporing_one_task() // { // Xunit.Assert.Equal(0, 1); // } // // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_all_tasks_to_the_common_pool_on_importing_several_tasks() // { // Xunit.Assert.Equal(0, 1); // } // // // ========================================================================================== // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_one_task_to_one_client_pool() // { // Xunit.Assert.Equal(0, 1); // } // // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_all_tasks_to_one_client_pool() // { // Xunit.Assert.Equal(0, 1); // } // // // ========================================================================================== // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_one_task_to_all_client_pools() // { // Xunit.Assert.Equal(0, 1); // } // // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_all_tasks_to_all_client_pools() // { // Xunit.Assert.Equal(0, 1); // } // // // ========================================================================================== // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_no_tasks_to_not_matching_client_pools() // { // Xunit.Assert.Equal(0, 1); // } // // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_one_task_to_matching_client_pools() // { // Xunit.Assert.Equal(0, 1); // } // // [MbUnit.Framework.Test][NUnit.Framework.Test][Fact] // public void Should_add_all_tasks_to_matching_client_pools() // { // Xunit.Assert.Equal(0, 1); // } void GivenTasksForRule(ITestRun testRun, string rule) { TaskPool.TasksForClients.AddRange( new[] { new TestTask { Id = 1, TaskStatus = TestTaskStatuses.Running, Rule = rule, TestRunId = testRun.Id, WorkflowId = testRun.WorkflowId }, new TestTask { Id = 2, TaskStatus = TestTaskStatuses.New, IsCancel = true, Rule = rule, TestRunId = testRun.Id, WorkflowId = testRun.WorkflowId }, new TestTask { Id = 2, TaskStatus = TestTaskStatuses.New, Rule = rule, TestRunId = testRun.Id, WorkflowId = testRun.WorkflowId } } ); }
void THEN_testRun_is_running(ITestRun testRun) { Assert.Equal(true, testRun.IsActive()); }
void ThenTestRunIsRunning(ITestRun testRun) { Assert.Equal(true, testRun.IsActive()); }
public void RunTests(ITestRun selection) { FireFinishedEvent(); }
void ThenTestRunIsCompleted(ITestRun testRun) { Assert.Equal(true, testRun.IsCompleted()); }
public Task SaveResults(string runId, int suiteId) { return(Task.Factory.StartNew(() => { // tell the spinner this task is starting ViewModelLocator.MainWindowViewModel.TaskManager.AddTask(); // retrieve the info for the specified run RunInfo rfRunInfo = Services.Rainforest.Runs.GetSingle(runId); // check to see if the run is finished if (rfRunInfo.state != "complete" && rfRunInfo.state != "aborted") { ViewModelLocator.MainWindowViewModel.TaskManager.RemoveTask(); throw new Core.ServiceException(Core.Error.RunNotComplete, runId); } // run has completed or has been aborted and is being processed, tag can be removed this.TFS.RemoveTag(suiteId, $"RUNID{runId}"); // if run was aborted then drop results if (rfRunInfo.state == "aborted") { ViewModelLocator.MainWindowViewModel.TaskManager.RemoveTask(); throw new Core.ServiceException(Core.Error.RunAborted, runId); } // Run was completed successfully // deserialize the RF tests info that were in the run, ids here are all rfIds, these are NOT JsonObjects.Test objects var anon = new[] { new { id = 0, result = "" } }; var rfTestResults = JsonConvert.DeserializeAnonymousType(rfRunInfo.extras["tests"].ToString(), anon); // Get all the testpoints from the suite var testPointDict = TFS.Session.workingPlan .QueryTestPoints(String.Format("SELECT * FROM TestPoint WHERE SuiteId = {0}", suiteId)) .ToDictionary(tp => tp.TestCaseId, tp => tp); // create a run in tfs to create results against ITestRun tfsTestRun = Session.workingPlan.CreateTestRun(false); // map the RF test results to a new enumerable with stored TFS id var refinedRFTestResults = rfTestResults.Select(r => { // retrieve the test from RF, need to search tag for matching TFS id // each should have a tag already as it was ensured before the run was created // TOEXPAND -> could possible add redundant check for no tags found in case manually removed Test rfTest = Services.Rainforest.Tests.GetSingle(r.id.ToString()); string tfsId = Parse.ExtractIdFromTags("TFSID", rfTest.tags); return new { rfid = r.id, verdict = r.result, tfsId = Int32.Parse(tfsId) }; }) .ToList(); // go through RF results once to find the needed testpoints and add to run foreach (var result in refinedRFTestResults) { // find test point for the matching TFS tc and add to run ITestPoint testPoint = testPointDict[result.tfsId]; tfsTestRun.AddTestPoint(testPoint, testPoint.TestCaseWorkItem.Owner); } tfsTestRun.Save(); // retrieve all the TFS results from the run Dictionary <int, ITestCaseResult> tfsTestResults = tfsTestRun.QueryResults().ToDictionary(r => r.TestCaseId, r => r); // go through RF results again to save the outcomes to the tfs results foreach (var result in refinedRFTestResults) { ITestCaseResult tfsResult = tfsTestResults[result.tfsId]; switch (result.verdict) { case "passed": tfsResult.Outcome = TestOutcome.Passed; tfsResult.State = TestResultState.Completed; break; case "failed": tfsResult.Outcome = TestOutcome.Failed; tfsResult.State = TestResultState.Completed; break; default: // TOEXPAND -> should never get here, verdict will always have a value break; } tfsResult.State = TestResultState.Completed; tfsResult.RunBy = Session.userTFId; tfsResult.Save(); } tfsTestRun.Save(); tfsTestRun.Refresh(); // tell the spinner this task is done ViewModelLocator.MainWindowViewModel.TaskManager.RemoveTask(); })); }
public void RunTests(ITestRun testRun) { throw new Exception("The method or operation is not implemented."); }
private MyTestListener ExecuteLoaderAndListen(ITestRun testRun) { var loader = new Loader(_assemblyPathName); var listener = new MyTestListener(loader); loader.RunTests(testRun); do { Thread.Sleep(200); } while (listener.TestsRunning); loader.Dispose(); Thread.SpinWait(20); return listener; }
// TODO: remove duplication // void SetCommonData(ITestRun testRun, ICommonData commonData) // { // if (null == commonData || 0 >= commonData.Data.Count) // return; // foreach (var pair in commonData.Data) // AddOrUpdateDataItem(testRun, commonData.Data, pair.Key); // } void SetCreatedTime(ITestRun testRun) { testRun.CreatedTime = DateTime.Now; }
public void RunTests(ITestRun testRun) { _testRun = testRun; StartWorkerThread(); }
void THEN_testRun_is_pending(ITestRun testRun) { Assert.Equal(true, testRun.IsPending()); }
public void Execute(ITestRun testRun, ITestListener listener) { Use(listener); try { SafeCurrentDirectory(); if( CreateObject() && FixtureSetUp() ) { foreach( var testMethod in _testMethods ) { if( !testMethod.Ignore ) { if( testRun.Contains(testMethod) && SetUp(testMethod) ) { testMethod.Execute(_testListener); TearDown(testMethod); } } else { _testListener.OnTestSkipped(new TestFixtureInfo(this), new TestResultEventArgs( AssemblyName, FullName, testMethod.Name, testMethod.IgnoreReason, 0){TestResult = TestResultCategory.Skipped}); } } FixtureTearDown(); } } finally { RestoreCurrentDirectory(); } }
public void RunTests(ITestRun testSelection, ITestListener listener) { SetUp(); foreach( var tc in TestFixtures ) { if( testSelection.Contains(tc) ) { if(!tc.IsIgnored) { tc.Execute(testSelection, listener); } else { listener.OnTestSkipped(this, new TestResultEventArgs( FullName, tc.FullName, string.Empty, tc.IgnoreReason, 0)); } } } TearDown(); }
public void RunTests(ITestRun testRun) { _testRun = testRun; StartWorkerThread(); }