/// <summary> /// Clean up the host side. /// We do the following steps. Each step is important and must be done whenever previous step throws or not. /// - Call HostSide.Cleanup. /// - Ask Runner IDE to detach debugger (if attached). /// - Dispose m_vsIde. /// This should not throw. /// </summary> private void CleanupHostSide() { lock (_hostSideLock) { Contract.Assert(HostSide != null); if (HostSide != null) { try { HostSide.Cleanup(); } catch (Exception ex) // We don't know what this can throw in advance. { SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter failed to call ITestAdapter.Cleanup: {0}", ex), TestOutcome.Warning); } } try { Contract.Assert(_vsIde != null); _vsIde.Dispose(); } catch (Exception ex) { SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter: error shutting down VS IDE: {0}", ex), TestOutcome.Warning); } _vsIde = null; _hostSide = null; // Note: host side lifetime is controlled by the addin. } }
private ITestAdapter GetTestAdapter(ITestElement test) { Debug.Assert(test != null, "Internal error: test is null!"); // Get more metadata off the type. string id = test.HumanReadableId; int lastDot = id.LastIndexOf('.'); string typeName = id.Substring(0, lastDot); Type dynamicHostType = DynamicHostTypeAttribute.GetDynamicHostType(test.Name, typeName, test.Storage); string dynamicHostTypeName = dynamicHostType.FullName; ITestAdapter realTestAdapter = null; bool containsAdapter = m_adapters.TryGetValue(dynamicHostTypeName, out realTestAdapter); if (!containsAdapter) { realTestAdapter = (ITestAdapter)Activator.CreateInstance(dynamicHostType, new Object[] { }); // Iniitialize was delayed to be run from the Run method. realTestAdapter.Initialize(m_runContext); m_adapters.Add(dynamicHostTypeName, realTestAdapter); } return(realTestAdapter); }
private void CleanupHostSide() { lock (m_hostSideLock) { Debug.Assert(HostSide != null); if (HostSide != null) { try { ((ITestAdapter)HostSide).Cleanup(); } catch (Exception ex) // We don't know what this can throw in advance. { SendResult(string.Format(CultureInfo.InvariantCulture, Resources.FailedToCallTACleanup, ex), TestOutcome.Warning); } } try { Debug.Assert(m_vsIde != null); m_vsIde.Dispose(); } catch (Exception ex) { SendResult(string.Format(CultureInfo.InvariantCulture, Resources.ErrorShuttingDownVS, ex), TestOutcome.Warning); } m_vsIde = null; m_hostSide = null; // Note: host side lifetime is controlled by the addin. } }
private void CreateHostSide() { // Note: we already have try-catch-Debug.Fail in Initialize that calls this method. // Note: registryHive can be null when using HostType attribute. In this case we'll use default hive. Debug.Assert(!string.IsNullOrEmpty(m_workingDir)); // Note: registryHive can be null when using the attribute. That's OK, VsIde will figure out. Debug.Assert(!string.IsNullOrEmpty(m_workingDir)); Debug.Assert(m_hostSide == null, "HA.CreateHostSide: m_hostSide should be null (ignorable)."); Debug.Assert(m_vsIde == null, "HA.CreateHostSide: m_vsIde should be null (ignorable)."); // Start devenv. m_vsIde = new VisualStudioIde(new VsIdeStartupInfo(m_vsRegistryHive, m_workingDir)); m_vsIde.ErrorHandler += HostProcessErrorHandler; Stopwatch timer = Stopwatch.StartNew(); do { try { m_vsIde.Dte.MainWindow.Visible = true; // This could be in TestRunConfig options for this host type. break; } catch (Exception) { } System.Threading.Thread.Sleep(RegistrySettings.BaseSleepDuration); } while (timer.Elapsed < s_ideStartupTimeout); m_hostSide = GetHostSideFromAddin(); }
/// <summary> /// Starts new Visual Studio process and obtains host side from it. /// </summary> private void CreateHostSide() { Contract.Assert(!string.IsNullOrEmpty(_workingDir)); Contract.Assert(_hostSide == null); Contract.Assert(_vsIde == null); // Start devenv. _vsIde = new VisualStudioIde(new VsIdeStartupInfo(_vsRegistryHive, _workingDir)); _vsIde.ErrorHandler += HostProcessErrorHandler; Stopwatch timer = Stopwatch.StartNew(); do { try { _vsIde.Dte.MainWindow.Visible = true; // This could be in TestRunConfig options for this host type. break; } catch (Exception) { } System.Threading.Thread.Sleep(_baseSleepDuration); } while (timer.Elapsed < _ideStartupTimeout); _hostSide = GetHostSideFromAddin(); }
/// <summary> /// IBaseAdapter method: called to execute a test. /// </summary> /// <param name="testElement">The test object to run</param> /// <param name="testContext">The Test conext for this test invocation</param> void IBaseAdapter.Run(ITestElement testElement, ITestContext testContext) { Trace.TraceInformation("Called DynamicHostAdapter.Run"); ITestAdapter realAdapter = GetTestAdapter(testElement); realAdapter.Run(testElement, testContext); }
public void Setup() { var type = Assembly.LoadFrom($"..\\{Version}.Adapter\\{Version}.Adapter.dll") .GetType($"{Version}.Adapter.TestAdapter"); Adapter = (ITestAdapter)Activator.CreateInstance(type); Adapter.Container = Adapter.CreateContainer(); }
private ITestAdapter GetHostSideFromAddin() { // Find the Addin. // Note: After VS starts addin needs some time to load, so we try a few times. AddIn addinLookingFor = null; Stopwatch timer = Stopwatch.StartNew(); try { do { try { // There is no index-by-name API, so we have to check all addins. foreach (AddIn addin in m_vsIde.Dte.AddIns) { if (addin.Name == Constants.VsAddinName) { addinLookingFor = addin; break; } } } catch (Exception) { // Catch all exceptions to prevent intermittent failures such as COMException (0x8001010A) // while VS has not started yet. Just retry again until we timeout. } if (addinLookingFor != null) { break; } System.Threading.Thread.Sleep(RegistrySettings.BaseSleepDuration); } while (timer.Elapsed < s_addinWaitTimeout); } finally { timer.Stop(); } if (addinLookingFor == null) { Debug.Fail("HA.GetHostSideFromAddin: timed out but could not get the addin from VS."); throw new VsIdeTestHostException(Resources.TimedOutGettingAddin); } m_testHostAddin = (IVsIdeTestHostAddin)addinLookingFor.Object; ITestAdapter hostSide = m_testHostAddin.GetHostSide(); Debug.Assert(hostSide != null); return(hostSide); }
[Test] public void TestHtmlFileWithSrcFiles() { using (ITestAdapter adapter = JSNet.ClosureLibrary(basejsfile)) { ITestResults results = adapter.RunTest(@"resources\test_with_src_files.html"); Assert.AreEqual(0, results.Failed.Count(), results.ToString()); Assert.AreEqual(65, results.Passed.Count(), results.ToString()); } }
[Test] public void RunHtmlFileTest() { using (ITestAdapter adapter = JSNet.ClosureLibrary(basejsfile)) { ITestResults results = adapter.RunTest(@"J:\dev\Projects\Misc\closure-library\closure\goog\array\array_test.html"); Assert.AreEqual(0, results.Failed.Count(), results.ToString()); Assert.AreEqual(73, results.Passed.Count(), results.ToString()); } }
[Test] public void RunSingleTestFile() { using (ITestAdapter adapter = JSNet.QUnit(qUnitJS)) { ITestResults results = adapter.RunTest(@"J:\dev\libs\qunit\test\test.js"); Assert.AreEqual(2, results.Failed.Count()); Assert.AreEqual(23, results.Passed.Count()); } }
[Test] public void RunJSFileTest() { using (ITestAdapter adapter = JSNet.ClosureLibrary(basejsfile)) { ITestResults results = adapter.RunTest(@"resources\simple_closure_tests.js"); Assert.AreEqual(0, results.Failed.Count(), results.ToString()); Assert.AreEqual(66, results.Passed.Count(), results.ToString()); } }
/// <summary> /// IBaseAdapter method: called to execute a test. /// </summary> /// <param name="testElement">The test object to run</param> /// <param name="testContext">The Test conext for this test invocation</param> void IBaseAdapter.Run(ITestElement testElement, ITestContext testContext) { Trace.TraceInformation("Called MtaHostAdapter.Run"); ITestAdapter realAdapter = GetTestAdapter(testElement); RunOnMtaThread(() => { realAdapter.Run(testElement, testContext); }); }
/// <summary> /// Obtain host side from the addin. /// </summary> /// <returns></returns> private ITestAdapter GetHostSideFromAddin() { // Find the Addin. // Note: After VS starts addin needs some time to load, so we try a few times. AddIn addinLookingFor = null; Stopwatch timer = Stopwatch.StartNew(); try { do { try { // There is no index-by-name API, so we have to check all addins. foreach (AddIn addin in _vsIde.Dte.AddIns) { if (addin.Name == VsAddinName) { addinLookingFor = addin; break; } } } catch (Exception) { // Catch all exceptions to prevent intermittent failures such as COMException (0x8001010A) // while VS has not started yet. Just retry again until we timeout. } if (addinLookingFor != null) { break; } System.Threading.Thread.Sleep(_baseSleepDuration); } while (timer.Elapsed < _addinWaitTimeout); } finally { timer.Stop(); } if (addinLookingFor == null) { throw new VsIdeTestHostException("Timed out getting Vs Ide Test Host Add-in from Visual Studio. Please make sure that the Add-in is installed and started when VS starts (use Tools->Add-in Manager)."); } _testHostAddin = (IVsIdeTestHostAddin)addinLookingFor.Object; ITestAdapter hostSide = _testHostAddin.GetHostSide(); Contract.Assert(hostSide != null); return(hostSide); }
[Test] public void AssertThatTheClosureTestWorksWithoutAnyCoverageStuff() { using (ITestAdapter adapter = JSNet.ClosureLibrary(basejsfile)) { adapter.LoadSourceFile(@"resources\jscoverage\src\jscoverage_source.js"); ITestResults results = adapter.RunTest(@"resources\jscoverage\jscoverage_test.js"); Assert.AreEqual(0, results.Failed.Count(), results.ToString()); Assert.AreEqual(4, results.Passed.Count(), results.ToString()); } }
private static ITestAdapter CreateRemoteShim() { IIsolatedEnvironment environment = SharedEnvironmentManager.GetSharedEnvironment(); environment.Loader.AddHintDirectory(GetVSTSDirectoryPath()); Type shimType = typeof(Shim); ITestAdapter shim = (ITestAdapter)environment.AppDomain.CreateInstanceAndUnwrap(shimType.Assembly.FullName, shimType.FullName); return(shim); }
void IBaseAdapter.Run(ITestElement testElement, ITestContext testContext) { UIThreadInvoker.Initialize(); UIThreadInvoker.Invoke((ThreadInvoker) delegate() { ITestAdapter realAdapter = GetTestAdapter(testElement); realAdapter.Run(testElement, testContext); Trace.TraceInformation("Completed UI thread call to Run"); }); Trace.TraceInformation("Completed incoming call to Run"); }
[Test] public void SucceedingTests() { using (ITestAdapter adapter = JSNet.JSUnit(jsUnitCoreFile)) { ITestResults results = adapter.RunTest(@"J:\dev\libs\jsunit\tests\jsUnitAssertionTests.html"); Assert.AreEqual(0, results.Failed.Count()); Assert.AreEqual(31, results.Passed.Count()); Assert.IsNotNull(results); Console.WriteLine(results); } }
[Test] public void RunFailingTests() { using (ITestAdapter adapter = JSNet.Jasmine(jasmineJsFile)) { adapter.LoadSourceFile(@"J:\dev\libs\jasmine\src\Player.js"); ITestResults results = adapter.RunTest(@"J:\dev\libs\jasmine\spec\PlayerSpec.js"); Assert.AreEqual(5, results.Failed.Count()); Assert.AreEqual(0, results.Passed.Count()); Assert.IsNotNull(results); Console.WriteLine(results); } }
private ITestResults RunSingleTest(string file) { Trace.Assert(!String.IsNullOrWhiteSpace(file)); Trace.Assert(File.Exists(file), string.Format("Could not find file '{0}'", file)); using (ITestAdapter adapter = GetAdapter()) { foreach (string globalFile in globalSourceFiles) { adapter.LoadSourceFile(globalFile); } return(adapter.RunTest(file)); } }
/// <summary> /// Get real TA. /// </summary> private ITestAdapter GetTestAdapter(ITestElement test) { Debug.Assert(test != null, "Internal error: test is null!"); Debug.Assert(!string.IsNullOrEmpty(test.Adapter), "Internal error: test.Adapter is null or empty!"); ITestAdapter realTestAdapter = null; bool containsAdapter = m_adapters.TryGetValue(test.Adapter, out realTestAdapter); if (!containsAdapter) { realTestAdapter = (ITestAdapter)Activator.CreateInstance(Type.GetType(test.Adapter), new Object[] { }); // Initialize was delayed to be run from the Run method. realTestAdapter.Initialize(m_runContext); m_adapters.Add(test.Adapter, realTestAdapter); } return(realTestAdapter); }
/// <summary> /// Common logic for test both Anchorables and Documents /// </summary> /// <param name="adapter"></param> private void TestResetNotification(ITestAdapter adapter) { // Make sure we have the correct initial counts Assert.AreEqual(adapter.ExpectedCount, adapter.CollectionCount); Assert.AreEqual(adapter.ExpectedCount, adapter.SourceCount); // We are only expecting the newly added items AreEqual(adapter.Notifications, new NotifyActionCount { AddCount = adapter.ExpectedCount }); // Raise the Reset notification. Previous versions of AvalonDock assumed the collection was cleared. adapter.GetCollection().Refresh(); // Nothing should have changed Assert.AreEqual(adapter.ExpectedCount, adapter.CollectionCount); Assert.AreEqual(adapter.ExpectedCount, adapter.SourceCount); // Verify nothing has been closed and the Reset notification was received AreEqual(adapter.Notifications, new NotifyActionCount { AddCount = adapter.ExpectedCount, ResetCount = 1 }); // Close the odd items. This will also raise the Reset notification. var removeChildren = adapter.GetSource().Where((x, i) => i % 2 != 0).ToList(); adapter.GetCollection().RemoveRange(removeChildren); // Verify the remaining items int remainingCount = adapter.ExpectedCount - removeChildren.Count; Assert.AreEqual(remainingCount, adapter.CollectionCount); Assert.AreEqual(remainingCount, adapter.SourceCount); // NOTE: The RemoveCount is still zero because RemoveRange silently removed the items then issues a Reset. AreEqual(adapter.Notifications, new NotifyActionCount { AddCount = adapter.ExpectedCount, ResetCount = 2 }); }
void IBaseAdapter.Run(ITestElement testElement, ITestContext testContext) { Thread myThread = Thread.CurrentThread; try { // Make sure to abort the previous test's Run thread if it isn't done yet - this could happen if a test times out Thread threadToAbort; lock (m_runThreadLock) { threadToAbort = m_runThread; m_runThread = myThread; } AbortThread(threadToAbort); //Register configuration proxy to merge test configuration with VS ConfigurationProxy.Register(testElement.Storage); ITestAdapter realAdapter = GetTestAdapter(testElement); realAdapter.Run(testElement, testContext); } catch (ThreadAbortException) { // The agent-side adapter's thread that called this method may have already been aborted due to a timeout, so // don't send this exception back Thread.ResetAbort(); } finally { lock (m_runThreadLock) { if (m_runThread != null && m_runThread.ManagedThreadId == myThread.ManagedThreadId) { m_runThread = null; } } } }
public static ICoverageAdapter JSCoverage(ITestAdapter testAdapter) { return new JSCoverageTestAdapter(testAdapter); }
public JSCoverageTestAdapter(ITestAdapter testAdapter) { Trace.Assert(testAdapter != null); this.testAdapter = testAdapter; }
public MarshalByRefTestAdapterProxy(ITestAdapter target) { this.target = target; }
public TestCodeRunner(ITestAdapter testAdapter) { _testAdapter = testAdapter; }
/// <summary> /// Setting test model which determines test structure /// </summary> /// <param name="model">Test Adapter</param> public void SetTestModel(ITestAdapter model) { mTestModel = model; }
public void SetUp() { const string basejsfile = @"J:\dev\Projects\Misc\closure-library\closure\goog\base.js"; ctx = JSNet.ClosureLibrary(basejsfile); }
public static ICoverageAdapter JSCoverage(ITestAdapter testAdapter) { return(new JSCoverageTestAdapter(testAdapter)); }
public TestGenerator(ITestAdapter model, WordSet wordSet) { mTestModel = model; mWordSet = wordSet; mSelector = new WordSelector(new EasyModeWordSelectionStrategy(), wordSet); }
[SetUp] public void SetUp() { const string basejsfile = @"J:\dev\Projects\Misc\closure-library\closure\goog\base.js"; ctx = JSNet.ClosureLibrary(basejsfile); }
void IBaseAdapter.Run(ITestElement testElement, ITestContext testContext) { ITestAdapter realAdapter = GetTestAdapter(testElement); realAdapter.Run(testElement, testContext); }
/// <summary> /// Clean up the host side. /// We do the following steps. Each step is important and must be done whenever previous step throws or not. /// - Call HostSide.Cleanup. /// - Ask Runner IDE to detach debugger (if attached). /// - Dispose m_vsIde. /// This should not throw. /// </summary> private void CleanupHostSide() { lock (_hostSideLock) { Contract.Assert(HostSide != null); if (HostSide != null) { try { HostSide.Cleanup(); } catch (Exception ex) // We don't know what this can throw in advance. { SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter failed to call ITestAdapter.Cleanup: {0}", ex), TestOutcome.Warning); } } try { Contract.Assert(_vsIde != null); _vsIde.Dispose(); } catch (InvalidComObjectException) { // This exception is always thrown when quitting VS. Nothing // is gained by reporting it for every run. } catch (Exception ex) { SendResult(string.Format(CultureInfo.InvariantCulture, "Warning: VsIdeHostAdapter: error shutting down VS IDE: {0}", ex), TestOutcome.Warning); } _vsIde = null; _hostSide = null; // Note: host side lifetime is controlled by the addin. } }