public override bool Run(TestFilter filter, DiscoveryConverter discovery, NUnit3TestExecutor nUnit3TestExecutor) { filter = CheckVsTestFilter(filter, discovery, VsTestFilter); if (filter == NUnitTestFilterBuilder.NoTestsFound) { TestLog.Info(" Skipping assembly - no matching test cases found"); return(false); } return(base.Run(filter, discovery, nUnit3TestExecutor)); }
public void CanMakeTestCaseShouldBuildTraitsCache() { var xmlNodeList = FakeTestData.GetTestNodes(); var tf = Substitute.For <INUnitDiscoveryCanHaveTestCases>(); foreach (XmlNode node in xmlNodeList) { var xElem = XElement.Load(node.CreateNavigator().ReadSubtree()); var tc = DiscoveryConverter.ExtractTestCase(tf, xElem); var testCase = testConverter.ConvertTestCase(tc); } var traitsCache = testConverter.TraitsCache; Assert.Multiple(() => { // There are 12 ids in the TestXml2, but will be storing only ancestor properties. // Not the leaf node test-case properties. Assert.That(traitsCache.Keys.Count, Is.EqualTo(7)); // Even though ancestor doesn't have any properties. Will be storing their ids. // So that we will not make call SelectNodes call again. CheckNodesWithNoProperties(traitsCache); // Will not be storing leaf nodes test-case nodes in the cache. CheckNoTestCaseNodesExist(traitsCache); // Checking assembly level attribute. CheckNodeProperties(traitsCache, "0-1009", new[] { new KeyValuePair <string, string>("Category", "AsmCat") }); // Checking Class level attributes base class & dervied class CheckNodeProperties(traitsCache, "0-1000", new[] { new KeyValuePair <string, string>("Category", "BaseClass") }); CheckNodeProperties(traitsCache, "0-1002", new[] { new KeyValuePair <string, string>("Category", "DerivedClass"), new KeyValuePair <string, string>("Category", "BaseClass") }); // Checking Nested class attributes. CheckNodeProperties(traitsCache, "0-1005", new[] { new KeyValuePair <string, string>("Category", "NS1") }); CheckNodeProperties(traitsCache, "0-1007", new[] { new KeyValuePair <string, string>("Category", "NS2") }); }); }
public virtual bool Run(TestFilter filter, DiscoveryConverter discovery, NUnit3TestExecutor nUnit3TestExecutor) { filter = CheckFilterInCurrentMode(filter, discovery); nUnit3TestExecutor.Dump?.StartExecution(filter, "(At Execution)"); var converter = CreateConverter(discovery); using var listener = new NUnitEventListener(converter, nUnit3TestExecutor); try { var results = NUnitEngineAdapter.Run(listener, filter); NUnitEngineAdapter.GenerateTestOutput(results, discovery.AssemblyPath, TestOutputXmlFolder); } catch (NullReferenceException) { // this happens during the run when CancelRun is called. TestLog.Debug(" Null ref caught"); } return(true); }
public void SetUp() { var xDoc = XDocument.Parse(FakeTestData.TestXml); var parent = Substitute.For <INUnitDiscoveryCanHaveTestFixture>(); parent.Parent.Returns(null as INUnitDiscoverySuiteBase); var className = xDoc.Root.Attribute("classname").Value; var tf = DiscoveryConverter.ExtractTestFixture(parent, xDoc.Root, className); var tcs = DiscoveryConverter.ExtractTestCases(tf, xDoc.Root); Assert.That(tcs.Count(), Is.EqualTo(1), "Setup: More than one test case in fake data"); fakeTestNode = tcs.Single(); var settings = Substitute.For <IAdapterSettings>(); settings.ConsoleOut.Returns(0); settings.UseTestNameInConsoleOutput.Returns(false); settings.CollectSourceInformation.Returns(true); var discoveryConverter = Substitute.For <IDiscoveryConverter>(); testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, settings, discoveryConverter); }
private void RunAssembly(string assemblyPath, IGrouping <string, TestCase> testCases, TestFilter filter) { LogActionAndSelection(assemblyPath, filter); RestoreRandomSeed(assemblyPath); Dump = DumpXml.CreateDump(assemblyPath, testCases, Settings); try { var package = CreateTestPackage(assemblyPath, testCases); NUnitEngineAdapter.CreateRunner(package); CreateTestOutputFolder(); Dump?.StartDiscoveryInExecution(testCases, filter, package); // var discoveryResults = RunType == RunType.CommandLineCurrentNUnit ? null : NUnitEngineAdapter.Explore(filter); var discoveryResults = NUnitEngineAdapter.Explore(filter); Dump?.AddString(discoveryResults?.AsString() ?? " No discovery"); if (discoveryResults?.IsRunnable ?? true) { var discovery = new DiscoveryConverter(TestLog, Settings); discovery.Convert(discoveryResults, assemblyPath); if (!Settings.SkipExecutionWhenNoTests || discovery.AllTestCases.Any()) { var ea = ExecutionFactory.Create(this); ea.Run(filter, discovery, this); } else { TestLog.InfoNoTests(assemblyPath); } } else { TestLog.InfoNoTests(discoveryResults.HasNoNUnitTests, assemblyPath); } } catch (Exception ex) when(ex is BadImageFormatException || ex.InnerException is BadImageFormatException) { // we skip the native c++ binaries that we don't support. TestLog.Warning(" Assembly not supported: " + assemblyPath); } catch (FileNotFoundException ex) { // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here TestLog.Warning(" Dependent Assembly " + ex.FileName + " of " + assemblyPath + " not found. Can be ignored if not an NUnit project."); } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } TestLog.Warning(" Exception thrown executing tests in " + assemblyPath, ex); } finally { Dump?.DumpForExecution(); try { NUnitEngineAdapter?.CloseRunner(); } catch (Exception ex) { // can happen if CLR throws CannotUnloadAppDomainException, for example // due to a long-lasting operation in a protected region (catch/finally clause). if (ex is TargetInvocationException) { ex = ex.InnerException; } TestLog.Warning($" Exception thrown unloading tests from {assemblyPath}", ex); } } }
public override bool Run(TestFilter filter, DiscoveryConverter discovery, NUnit3TestExecutor nUnit3TestExecutor) { return(base.Run(filter, discovery, nUnit3TestExecutor)); }
protected ITestConverterCommon CreateConverter(DiscoveryConverter discovery) => Settings.DiscoveryMethod == DiscoveryMethod.Current ? discovery.TestConverter : discovery.TestConverterForXml;