/// <summary>
        /// Execute test cases.
        /// </summary>
        /// <param name="assembly">Assembly.</param>
        /// <param name="testInfos">Test infos.</param>
        /// <param name="executionListener">Execution listener.</param>
        /// <remarks>It uses xunit execution engine to execute the test cases.</remarks>
        public void Execute(string assembly, string data, IXUnitExecutionListener executionListener)
        {
            XUnitTestInfo[] testInfos = JsonConvert.DeserializeObject <XUnitTestInfo[]> (data);
            var             lookup    = new HashSet <string> ();

            foreach (var testInfo in testInfos)
            {
                lookup.Add(testInfo.Id);
            }

            // we don't want to run every test in the assembly
            // only the tests passed in "testInfos" argument
            using (var controller = new XunitFrontController(AppDomainSupport.Denied, assembly, null, false, null, new NullSourceInformationProvider()))
                using (var discoveryVisitor = new TestDiscoveryVisitor(tc => lookup.Contains(tc.UniqueID)))
                    using (var executionVisitor = new TestExecutionVisitor(executionListener)) {
                        controller.Find(false, discoveryVisitor, TestFrameworkOptions.ForDiscovery());
                        discoveryVisitor.Finished.WaitOne();

                        var options = TestFrameworkOptions.ForExecution();
                        options.SetDisableParallelization(true);
                        options.SetSynchronousMessageReporting(true);

                        controller.RunTests(discoveryVisitor.TestCases, executionVisitor, options);
                    }
        }
        /// <summary>
        /// Builds the test info.
        /// </summary>
        /// <returns>The test info.</returns>
        /// <param name="assembly">Assembly.</param>
        /// <remarks>It uses xunit built-in function to load test case info from the test assembly.</remarks>
        XUnitTestInfo BuildTestInfo(string assembly)
        {
            var infos = new List <TestCaseInfo> ();

            if (assembly != null && File.Exists(assembly))
            {
                using (var controller = new XunitFrontController(AppDomainSupport.Denied, assembly, null, false, null, new NullSourceInformationProvider()))
                    using (var discoveryVisitor = new TestDiscoveryVisitor()) {
                        controller.Find(false, discoveryVisitor, TestFrameworkOptions.ForDiscovery());
                        discoveryVisitor.Finished.WaitOne();

                        foreach (var testCase in discoveryVisitor.TestCases)
                        {
                            infos.Add(new TestCaseInfo {
                                Id          = testCase.UniqueID,
                                Type        = testCase.TestMethod.TestClass.Class.Name,
                                Method      = testCase.TestMethod.Method.Name,
                                DisplayName = testCase.DisplayName,
                                Args        = testCase.TestMethodArguments
                            });
                        }
                    }

                // sort by type, method
                infos.Sort((info1, info2) => {
                    int i = info1.Type.CompareTo(info2.Type);
                    if (i == 0)
                    {
                        i = info1.Method.CompareTo(info2.Method);
                    }
                    return(i);
                });
            }

            var testInfo = new XUnitTestInfo();

            BuildTestInfo(testInfo, infos, 0);
            return(testInfo);
        }
Example #3
0
        public void Execute(string assembly, XUnitTestInfo[] testInfos, IXUnitExecutionListener executionListener)
        {
            var lookup = new HashSet <string> ();

            foreach (var testInfo in testInfos)
            {
                lookup.Add(testInfo.Id);
            }

            // we don't want to run every test in the assembly
            // only the tests passed in "testInfos" argument
            using (var controller = new XunitFrontController(assembly, null, false))
                using (var discoveryVisitor = new TestDiscoveryVisitor(tc => lookup.Contains(tc.UniqueID)))
                    using (var executionVisitor = new TestExecutionVisitor(executionListener)) {
                        controller.Find(false, discoveryVisitor, new TestFrameworkOptions());
                        discoveryVisitor.Finished.WaitOne();

                        controller.RunTests(discoveryVisitor.TestCases, executionVisitor,
                                            new XunitExecutionOptions {
                            DisableParallelization = true, SynchronousMessageReporting = true
                        });
                    }
        }