Пример #1
0
        private static void Main()
        {
            if (string.IsNullOrWhiteSpace(YourName.Authors))
            {
                Console.WriteLine("Enter your surnames at YourName.cs in AUTHORS constant");
                Thread.Sleep(3000);
                return;
            }
            var testPackage = new TestPackage(Assembly.GetExecutingAssembly().Location);

            using (var engine = new TestEngine())
                using (var testRunner = engine.GetRunner(testPackage))
                    if (TestsAreValid(testRunner))
                    {
                        var incorrectImplementations = ChallengeHelpers.GetIncorrectImplementationTypes();
                        var statuses = GetIncorrectImplementationsResults(testRunner, incorrectImplementations);
                        var res      = new List <ImplementationStatus>();
                        foreach (var status in statuses)
                        {
                            res.Add(status);
                            WriteImplementationStatusToConsole(status);
                        }
                        if (!string.IsNullOrWhiteSpace(YourName.Authors))
                        {
                            PostResults(res);
                        }
                    }
        }
Пример #2
0
        public void LoadTests(IList <string> files)
        {
            if (IsPackageLoaded)
            {
                UnloadTests();
            }

            _events.FireTestsLoading(files);

            TestFiles.Clear();
            TestFiles.AddRange(files);

            TestPackage         = MakeTestPackage(files);
            _lastRunWasDebugRun = false;

            Runner = TestEngine.GetRunner(TestPackage);
            Tests  = new TestNode(Runner.Explore(TestFilter.Empty));

            MapTestsToPackages();
            AvailableCategories = GetAvailableCategories();

            Results.Clear();

            _assemblyWatcher.Setup(1000, files as IList);
            _assemblyWatcher.AssemblyChanged += (path) => _events.FireTestChanged();
            _assemblyWatcher.Start();

            _events.FireTestLoaded(Tests);

            foreach (var subPackage in TestPackage.SubPackages)
            {
                Services.RecentFiles.Latest = subPackage.FullName;
            }
        }
Пример #3
0
        /// <summary>
        /// Run the test suite in the given project (dll and project name) with
        /// the configured TestFilterWhere. For the path resolution to work,
        /// the test project must be located in the same directory as the
        /// asp.net project. For the Where syntax, see
        /// NUnit.Engine.TestSelectionParser.ParseFilterElement()
        /// </summary>
        /// <param name="testproject"></param>
        public void Run(string testproject)
        {
            // To avoid a cyclic project dependency, the test DLL must be read
            // from an explicit path in the file system, and in .NET Code,
            // it additionally must be formally referenced, therefore the
            // diff / if errorlevel 1 xcopy construct in the post build event
            // to avoid endlessly recompiling a newer, but identical DLL
            // in a cyclic dependency loop.
            var approot = Environment.ContentRootPath;
            var dll     = Path.Combine(approot, @"..\bin", testproject + ".dll");
            var package = new TestPackage(dll); // no TestEngineActivator.CreateInstance() in nunit.engine.netstandard

            // NUnit.EnginePackageSettings
            package.AddSetting("ProcessModel", "Single");
            package.AddSetting("DomainUsage", "None");  // irrelevant in core

            using (var engine = new TestEngine())
                using (var runner = engine.GetRunner(package))
                {
                    var filter = TestFilter.Empty;
                    var where = Configuration["TestFilterWhere"];
                    if (!String.IsNullOrWhiteSpace(where))
                    {
                        var builder = new TestFilterBuilder();
                        builder.SelectWhere(where);
                        filter = builder.GetFilter(); // returns TestFilter.Empty when no TestFilterWhere is given
                    }
                    TestRunnerBase.Result = runner.Run(this, filter);
                }
        }
Пример #4
0
        public void LoadTests(IList <string> files)
        {
            if (IsPackageLoaded)
            {
                UnloadTests();
            }

            TestFiles.Clear();
            TestFiles.AddRange(files);
            _events.FireTestsLoading(files);

            TestPackage         = MakeTestPackage(files);
            _lastRunWasDebugRun = false;

            Runner = TestEngine.GetRunner(TestPackage);
            Tests  = ExploreTestPackage(TestPackage);
            AvailableCategories = GetAvailableCategories();

            Results.Clear();

            _assemblyWatcher.Setup(1000, files as IList);
            _assemblyWatcher.AssemblyChanged += new AssemblyChangedHandler(OnChange);
            _assemblyWatcher.Start();
            _events.FireTestLoaded(Tests);

            foreach (var subPackage in TestPackage.SubPackages)
            {
                Services.RecentFiles.SetMostRecent(subPackage.FullName);
            }
        }
Пример #5
0
        protected ITestRunner GetRunnerFor(string assemblyName, IGrouping <string, TestCase> testCases)

        {
            var package = CreateTestPackage(assemblyName, testCases);

            return(TestEngine.GetRunner(package));
        }
Пример #6
0
        public void LoadTests(IList <string> files)
        {
            if (IsPackageLoaded)
            {
                UnloadTests();
            }

            TestFiles.Clear();
            TestFiles.AddRange(files);
            _events.FireTestsLoading(files);

            TestPackage = MakeTestPackage(files);

            Runner = TestEngine.GetRunner(TestPackage);

            Tests = new TestNode(Runner.Explore(TestFilter.Empty));
            AvailableCategories = GetAvailableCategories();

            Results.Clear();

            _events.FireTestLoaded(Tests);

            foreach (var subPackage in TestPackage.SubPackages)
            {
                Services.RecentFiles.SetMostRecent(subPackage.FullName);
            }
        }
Пример #7
0
        protected ITestRunner GetRunnerFor(string assemblyName)
        {
            var package = CreateTestPackage(assemblyName);

            try
            {
                return(TestEngine.GetRunner(package));
            }
            catch (Exception ex)
            {
                TestLog.Error("Error: Unable to get runner for this assembly. Check installation, including any extensions.");
                TestLog.Error(ex.GetType().Name + ": " + ex.Message);
                throw;
            }
        }
Пример #8
0
        private static void RunTests(string assemblyPath)
        {
            var package = new TestPackage(assemblyPath);
            var engine  = new TestEngine();
            var runner  = engine.GetRunner(package);

            XmlNode result        = runner.Run(new TestListener(), TestFilter.Empty);
            string  overallResult = result.GetAttribute("result");

            Console.WriteLine("Test Run for {0} {1}", assemblyPath, result.GetAttribute("result"));
            Console.WriteLine("    Passing Tests:      {0}", result.GetAttribute("passed"));
            Console.WriteLine("    Failing Tests:      {0}", result.GetAttribute("failed"));
            Console.WriteLine("    Inconclusive Tests: {0}", result.GetAttribute("inconclusive"));
            Console.WriteLine("    Skipped Tests:      {0}", result.GetAttribute("skipped"));
            Console.WriteLine();
        }
Пример #9
0
        /// <summary>
        /// Executes the specified features.
        /// </summary>
        private void ExecuteFeatures()
        {
            FireExecutionStartEvent();

            TestPackage testPackage =
                NUnitEngineHelper.CreateTestPackage(new List <string> {
                _configuration.TestAssemblyFullName
            });

            TestFilter testFilter =
                NUnitEngineHelper.CreateTestFilter(_testAssembly, _configuration.Features);

            ITestRunner testRunner = _testEngine.GetRunner(testPackage);

            // TODO: Not sure if we need to keep this
            //_testSuite = NUnitEngineHelper.ParseTestRun(testRunner.Explore(testFilter)).TestSuite;

            CustomTestEventListener testEventListener = new CustomTestEventListener();

            // TODO: Not sure if we need to keep this
            //testEventListener.TestReport += OnTestReport;

            // TODO: Not sure if we need to keep this
            //NUnitEngineHelper.ParseTestRun(testRunner.Run(testEventListener, testFilter));

            RunSummary.CurrentFeature  = _features.First();
            RunSummary.CurrentScenario = RunSummary.CurrentFeature.Scenarios.First();
            RunSummary.CurrentStep     = RunSummary.CurrentScenario.Steps.First();

            RunSummary.FeatureCount  = _features.Count;
            RunSummary.ScenarioCount = _features.SelectMany(x => x.Scenarios).Count();
            RunSummary.StepCount     = _features.SelectMany(x => x.Scenarios).SelectMany(x => x.Steps).Count();

            testRunner.Run(testEventListener, testFilter);

            testRunner.StopRun(true);

            //while (testRunner.IsTestRunning) { }

            testRunner.Unload();
            testRunner.Dispose();

            _testEngine.Services.ServiceManager.StopServices();
            _testEngine.Services.ServiceManager.ClearServices();
            _testEngine.Services.ServiceManager.Dispose();
        }
Пример #10
0
        private static void Main()
        {
            names = LoadOrRequestName();
            var testPackage = new TestPackage(Assembly.GetExecutingAssembly().Location);

            using (var engine = new TestEngine())
                using (var testRunner = engine.GetRunner(testPackage))
                    if (TestsAreValid(testRunner))
                    {
                        var incorrectImplementations = ChallengeHelpers.GetIncorrectImplementationTypes();
                        var statuses = GetIncorrectImplementationsResults(testRunner, incorrectImplementations);
                        PostResults(statuses);
                        foreach (var status in statuses)
                        {
                            WriteImplementationStatusToConsole(status);
                        }
                    }
        }
Пример #11
0
        static void Main(string[] args)
        {
            var testAssemblyPath = @"C:\src\qata\src\tests\external\SomethingProject.Tests\bin\Debug\net461\SomethingProject.Tests.dll";
            var package          = new TestPackage(testAssemblyPath);
            var testEngine       = new TestEngine();
            var runner           = testEngine.GetRunner(package);
            var nUnitXml         = runner.Explore(TestFilter.Empty);
            var session          = new DiaSession(testAssemblyPath);

            foreach (XmlNode testNode in nUnitXml.SelectNodes("//test-case"))
            {
                var testName       = testNode.Attributes["fullname"]?.Value;
                var className      = testNode.Attributes["classname"]?.Value;
                var methodName     = testNode.Attributes["methodname"]?.Value;
                var navigationData = session.GetNavigationData(className, methodName);
                Console.WriteLine($"{testName} - {navigationData.FileName} - {navigationData.MinLineNumber}.");
            }
        }
Пример #12
0
        // Load Tests without sending events
        private void LoadAllTests(IList <string> files)
        {
            TestFiles.Clear();
            TestFiles.AddRange(files);

            TestPackage         = MakeTestPackage(files);
            _lastRunWasDebugRun = false;

            Runner = TestEngine.GetRunner(TestPackage);
            Tests  = new TestNode(Runner.Explore(TestFilter.Empty));
            AvailableCategories = GetAvailableCategories();

            Results.Clear();

            _assemblyWatcher.Setup(1000, files as IList);
            _assemblyWatcher.AssemblyChanged += (path) => _events.FireTestChanged();
            _assemblyWatcher.Start();
        }
Пример #13
0
        public Task <TestSuiteResult> RunTestsAsync(string dllPath)
        {
            return(Task.Run(() =>
            {
                var package = new TestPackage(dllPath);

                using (var engine = new TestEngine())
                {
                    engine.Services.Add(new SettingsService(false));
                    engine.Services.Add(new ExtensionService());
                    engine.Services.Add(new DriverService());
                    engine.Services.Add(new InProcessTestRunnerFactory());
                    engine.Services.Add(new ProjectService());          // +
                    engine.Services.Add(new RuntimeFrameworkService()); // +
                    engine.Services.Add(new TestFilterService());       // +
                    engine.Services.Add(new DomainManager());           // -
                    engine.Services.Add(new ResultService());
                    engine.Services.ServiceManager.StartServices();

                    using (global::NUnit.Engine.ITestRunner runner = engine.GetRunner(package))
                    {
                        try
                        {
                            var filter = TestFilter.Empty;
                            var result = runner.Run(new TestEventDispatcher(), filter);

                            if (result == null)
                            {
                                return TestSuiteResult.Error("No results", TimeSpan.Zero);
                            }

                            runner.Unload();
                            var parsedResults = CreateResult(result);
                            return parsedResults;
                        }
                        catch (Exception ex)
                        {
                            TryStopRunner(runner);
                            return TestSuiteResult.Error($"Unkown nunit error: {ex.Message}", TimeSpan.Zero);
                        }
                    }
                }
            }));
        }
Пример #14
0
        public void ReloadTests()
        {
            _events.FireTestsReloading();

            // NOTE: The `ITestRunner.Reload` method supported by the engine
            // has some problems, so we simulate Unload+Load. See issue #328.

            // Replace Runner in case settings changed
            Runner.Unload();
            Runner.Dispose();
            Runner = TestEngine.GetRunner(TestPackage);

            // Discover tests
            Tests = new TestNode(Runner.Explore(TestFilter.Empty));
            AvailableCategories = GetAvailableCategories();

            Results.Clear();

            _events.FireTestReloaded(Tests);
        }
Пример #15
0
        public static void Main()
        {
            var testPackage = new TestPackage(Assembly.GetExecutingAssembly().Location);

            using (var engine = new TestEngine())
                using (var testRunner = engine.GetRunner(testPackage))
                    if (TestsAreValid(testRunner))
                    {
                        var incorrectImplementations = IncorrectImplementationHelper.GetTypes();
                        var results = GetIncorrectImplementationResults(testRunner, incorrectImplementations).ToList();

                        var task1Results = results.Take(4);
                        var task2Results = results.Skip(4).Take(6);
                        var task3Results = results.Skip(10);

                        Console.WriteLine();
                        Console.WriteLine("Task1. SumAbs");

                        foreach (var result in task1Results)
                        {
                            WriteImplementationResultToConsole(result);
                        }

                        Console.WriteLine();
                        Console.WriteLine("Task2. Move");

                        foreach (var result in task2Results)
                        {
                            WriteImplementationResultToConsole(result);
                        }

                        Console.WriteLine();
                        Console.WriteLine("Task3. Distinct");

                        foreach (var result in task3Results)
                        {
                            WriteImplementationResultToConsole(result);
                        }
                    }
        }
Пример #16
0
        private void SetTestDebuggingFlag(bool debuggingRequested)
        {
            // We need to re-create the test runner because settings such
            // as debugging have already been passed to the test runner.
            // For performance, only do this if we did run in a different mode than last time.
            if (_lastRunWasDebugRun != debuggingRequested)
            {
                foreach (var subPackage in TestPackage.SubPackages)
                {
                    subPackage.Settings["DebugTests"] = debuggingRequested;
                }

                Runner = TestEngine.GetRunner(TestPackage);
                Runner.Load();

                // It is not strictly necessary to load the tests
                // because the runner will do that automatically, however,
                // the initial test count will be incorrect causing UI crashes.

                _lastRunWasDebugRun = debuggingRequested;
            }
        }
Пример #17
0
        public void ReloadTests()
        {
            _events.FireTestsReloading();

            Runner.Unload();
            Results.Clear();
            Tests = null;

            TestPackage = MakeTestPackage(TestFiles);

            Runner = TestEngine.GetRunner(TestPackage);

            Tests = new TestNode(Runner.Explore(TestFilter.Empty));
            AvailableCategories = GetAvailableCategories();

            if (Services.UserSettings.Gui.ClearResultsOnReload)
            {
                Results.Clear();
            }

            _events.FireTestReloaded(Tests);
        }
Пример #18
0
        private static void Main()
        {
            if (WordsStatistics_Tests.Authors == "<ВАШИ ФАМИЛИИ>")
            {
                Console.WriteLine("Укажите ваши фамилии в классе WordStatistics_Tests в поле Authors!");
                Thread.Sleep(3000);
            }
            var testPackage = new TestPackage(Assembly.GetExecutingAssembly().Location);

            using (var engine = new TestEngine())
                using (var testRunner = engine.GetRunner(testPackage))
                    if (TestsAreValid(testRunner))
                    {
                        var incorrectImplementations = ChallengeHelpers.GetIncorrectImplementationTypes();
                        var statuses = GetIncorrectImplementationsResults(testRunner, incorrectImplementations);
                        var res      = new List <ImplementationStatus>();
                        foreach (var status in statuses)
                        {
                            res.Add(status);
                            WriteImplementationStatusToConsole(status);
                        }
                        PostResults(res);
                    }
        }
Пример #19
0
 public void CreateRunner(TestPackage testPackage)
 {
     package = testPackage;
     Runner  = TestEngine.GetRunner(package);
 }
        protected ITestRunner GetRunnerFor(string assemblyName)
        {
            var package = CreateTestPackage(assemblyName);

            return(TestEngine.GetRunner(package));
        }