コード例 #1
0
 private static string LoadDriver(IFrameworkDriver driver, string testFile, TestPackage subPackage)
 {
     try
     {
         return(driver.Load(testFile, subPackage.Settings));
     }
     catch (Exception ex) when(!(ex is NUnitEngineException))
     {
         throw new NUnitEngineException("An exception occurred in the driver while loading tests.", ex);
     }
 }
コード例 #2
0
        public void Initialize()
        {
            driver = Substitute.For <IFrameworkDriver>();

            var driverService = Substitute.For <IDriverService>();

            driverService.GetDriver(AppDomain.CurrentDomain, string.Empty, string.Empty, false).ReturnsForAnyArgs(driver);

            var serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.GetService <IDriverService>().Returns(driverService);

            directTestRunner = new EmptyDirectTestRunner(serviceLocator, new TestPackage("mock-assembly.dll"));
        }
コード例 #3
0
        public void Explore(string filePath, string expectedType)
        {
            IFrameworkDriver driver = GetDriver(filePath);
            var result = XmlHelper.CreateXmlNode(driver.Explore(TestFilter.Empty.Text));

            Assert.That(result.Name, Is.EqualTo("test-suite"));
            Assert.That(result.GetAttribute("id"), Is.EqualTo(EXPECTED_ID));
            Assert.That(result.GetAttribute("name"), Is.EqualTo(filePath));
            Assert.That(result.GetAttribute("fullname"), Is.EqualTo(Path.GetFullPath(filePath)));
            Assert.That(result.GetAttribute("type"), Is.EqualTo(expectedType));
            Assert.That(result.GetAttribute("runstate"), Is.EqualTo(_expectedRunState));
            Assert.That(result.GetAttribute("testcasecount"), Is.EqualTo("0"));
            Assert.That(GetSkipReason(result), Is.EqualTo(_expectedReason));
            Assert.That(result.SelectNodes("test-suite").Count, Is.EqualTo(0), "Result should not have child tests");
        }
コード例 #4
0
        /// <summary>
        /// Load a TestPackage for exploration or execution
        /// </summary>
        /// <param name="package">The TestPackage to be loaded</param>
        /// <returns>A TestEngineResult.</returns>
        protected override TestEngineResult LoadPackage()
        {
            TestEngineResult result = new TestEngineResult();

            foreach (string testFile in TestPackage.TestFiles)
            {
                IFrameworkDriver driver = Services.DriverFactory.GetDriver(TestDomain, testFile, TestPackage.Settings);
                result.Add(driver.Load());
                _drivers.Add(driver);
            }

            return(IsProjectPackage(TestPackage)
                ? result.MakePackageResult(TestPackage.Name, TestPackage.FullName)
                : result);
        }
コード例 #5
0
        /// <summary>
        /// Load a TestPackage for exploration or execution
        /// </summary>
        /// <param name="package">The TestPackage to be loaded</param>
        /// <returns>A TestEngineResult.</returns>
        public override TestEngineResult Load(TestPackage package)
        {
            this.package = package;
            TestEngineResult result = new TestEngineResult();

            foreach (string testFile in package.TestFiles)
            {
                IFrameworkDriver driver = Services.DriverFactory.GetDriver(TestDomain, testFile, package.Settings);
                result.Add(driver.Load());
                drivers.Add(driver);
            }

            return(IsProjectPackage(this.package)
                ? result.MakePackageResult(package.Name, package.FullName)
                : result);
        }
コード例 #6
0
        /// <summary>
        /// Load a TestPackage for exploration or execution
        /// </summary>
        /// <returns>A TestEngineResult.</returns>
        protected override TestEngineResult LoadPackage()
        {
            var result = new TestEngineResult();

            // DirectRunner may be called with a single-assembly package
            // or a set of assemblies as subpackages.
            var packages = TestPackage.SubPackages;

            if (packages.Count == 0)
            {
                packages.Add(TestPackage);
            }

            var driverService = Services.GetService <IDriverService>();

            foreach (var subPackage in packages)
            {
                var testFile = subPackage.FullName;

                if (_assemblyResolver != null && !TestDomain.IsDefaultAppDomain() &&
                    subPackage.GetSetting(PackageSettings.ImageRequiresDefaultAppDomainAssemblyResolver, false))
                {
                    // It's OK to do this in the loop because the Add method
                    // checks to see if the path is already present.
                    _assemblyResolver.AddPathFromFile(testFile);
                }

                var targetFramework = subPackage.GetSetting(PackageSettings.ImageTargetFrameworkName, (string)null);

                IFrameworkDriver driver = driverService.GetDriver(TestDomain, testFile, targetFramework);
                driver.ID = TestPackage.ID;
                result.Add(driver.Load(testFile, subPackage.Settings));
                _drivers.Add(driver);
            }

            if (IsProjectPackage(TestPackage))
            {
                result = result.MakePackageResult(TestPackage.Name, TestPackage.FullName);
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Load a TestPackage for exploration or execution
        /// </summary>
        /// <returns>A TestEngineResult.</returns>
        protected override TestEngineResult LoadPackage()
        {
            var result = new TestEngineResult();

            // DirectRunner may be called with a single-assembly package
            // or a set of assemblies as subpackages.
            var packages = TestPackage.SubPackages;

            if (packages.Count == 0)
            {
                packages.Add(TestPackage);
            }

            var driverService = Services.GetService <IDriverService>();

            foreach (var subPackage in packages)
            {
                var testFile = subPackage.FullName;

                string targetFramework       = subPackage.GetSetting(InternalEnginePackageSettings.ImageTargetFrameworkName, (string)null);
                bool   skipNonTestAssemblies = subPackage.GetSetting(EnginePackageSettings.SkipNonTestAssemblies, false);

#if !NETSTANDARD1_6
                if (_assemblyResolver != null && !TestDomain.IsDefaultAppDomain() &&
                    subPackage.GetSetting(InternalEnginePackageSettings.ImageRequiresDefaultAppDomainAssemblyResolver, false))
                {
                    // It's OK to do this in the loop because the Add method
                    // checks to see if the path is already present.
                    _assemblyResolver.AddPathFromFile(testFile);
                }

                IFrameworkDriver driver = driverService.GetDriver(TestDomain, testFile, targetFramework, skipNonTestAssemblies);
#else
                IFrameworkDriver driver = driverService.GetDriver(testFile, skipNonTestAssemblies);
#endif
                driver.ID = TestPackage.ID;
                result.Add(LoadDriver(driver, testFile, subPackage));
                _drivers.Add(driver);
            }
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Load a TestPackage for exploration or execution
        /// </summary>
        /// <param name="package">The TestPackage to be loaded</param>
        /// <returns>A TestEngineResult.</returns>
        public override TestEngineResult Load(TestPackage package)
        {
            this.package = package;
            List <TestEngineResult> loadResults = new List <TestEngineResult>();

            foreach (string testFile in package.TestFiles)
            {
                // TODO: Should get the appropriate driver for the file
                IFrameworkDriver driver       = Services.DriverFactory.GetDriver(TestDomain, testFile, package.Settings);
                TestEngineResult driverResult = driver.Load();

                loadResults.Add(driverResult);

                if (!driverResult.HasErrors)
                {
                    drivers.Add(driver);
                }
            }

            return(MakePackageResult(loadResults));
        }
コード例 #9
0
        /// <summary>
        /// Load a TestPackage for exploration or execution
        /// </summary>
        /// <returns>A TestEngineResult.</returns>
        protected override TestEngineResult LoadPackage()
        {
            var result = new TestEngineResult();

            // DirectRunner may be called with a single-assembly package,
            // a set of assemblies as subpackages or even an arbitrary
            // hierarchy of packages and subpackages with assemblies
            // found in the terminal nodes.
            var packagesToLoad = TestPackage.Select(p => !p.HasSubPackages());

            var driverService = Services.GetService <IDriverService>();

            _drivers.Clear();

            foreach (var subPackage in packagesToLoad)
            {
                var testFile = subPackage.FullName;

                string targetFramework       = subPackage.GetSetting(InternalEnginePackageSettings.ImageTargetFrameworkName, (string)null);
                bool   skipNonTestAssemblies = subPackage.GetSetting(EnginePackageSettings.SkipNonTestAssemblies, false);

                if (_assemblyResolver != null && !TestDomain.IsDefaultAppDomain() &&
                    subPackage.GetSetting(InternalEnginePackageSettings.ImageRequiresDefaultAppDomainAssemblyResolver, false))
                {
                    // It's OK to do this in the loop because the Add method
                    // checks to see if the path is already present.
                    _assemblyResolver.AddPathFromFile(testFile);
                }

                IFrameworkDriver driver = driverService.GetDriver(TestDomain, testFile, targetFramework, skipNonTestAssemblies);

                driver.ID = subPackage.ID;
                result.Add(LoadDriver(driver, testFile, subPackage));
                _drivers.Add(driver);
            }
            return(result);
        }
コード例 #10
0
        public void CountTestCases(string filePath)
        {
            IFrameworkDriver driver = CreateDriver(filePath);

            Assert.That(driver.CountTestCases(TestFilter.Empty.Text), Is.EqualTo(0));
        }
コード例 #11
0
 public void CreateDriver()
 {
     _driver = new NotRunnableFrameworkDriver( BAD_FILE, REASON);
     _driver.ID = "99";
 }
コード例 #12
0
 public void CreateDriver()
 {
     _mockAssemblyPath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, MOCK_ASSEMBLY);
     _driver           = new NUnitNetStandardDriver();
 }
コード例 #13
0
 public void CreateDriver()
 {
     _driver    = new NotRunnableFrameworkDriver(BAD_FILE, REASON);
     _driver.ID = "99";
 }