예제 #1
0
        /// <summary>
        /// Starts running tests from a single type (if provided) or the whole assembly (if not). This call returns
        /// immediately, and status results are dispatched to the Info>s on this class. Callers can check <see cref="Status"/>
        /// to find out the current status.
        /// </summary>
        /// <param name="typeName">The (optional) type name of the single test class to run</param>
        /// <param name="diagnosticMessages">Set to <c>true</c> to enable diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        /// <param name="methodDisplay">Set to choose the default display name style for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="methodDisplayOptions">Set to choose the default display name style options for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="preEnumerateTheories">Set to <c>true</c> to pre-enumerate individual theory tests; set to <c>false</c> to use
        /// a single test case for the theory. By default, uses the value from the assembly configuration file. (This parameter is ignored
        /// for xUnit.net v1 tests.)</param>
        /// <param name="parallel">Set to <c>true</c> to run test collections in parallel; set to <c>false</c> to run them sequentially.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="maxParallelThreads">Set to 0 to use unlimited threads; set to any other positive integer to limit to an exact number
        /// of threads. By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="internalDiagnosticMessages">Set to <c>true</c> to enable internal diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        public void Discover(
            string typeName                 = null,
            bool?diagnosticMessages         = null,
            TestMethodDisplay?methodDisplay = null,
            TestMethodDisplayOptions?methodDisplayOptions = null,
            bool?preEnumerateTheories       = null,
            bool?internalDiagnosticMessages = null)
        {
            cancelled           = false;
            testCasesDiscovered = 0;
            testCasesToRun.Clear();

            XunitWorkerThread.QueueUserWorkItem(() =>
            {
                var discoveryOptions = GetDiscoveryOptions(diagnosticMessages, methodDisplay, methodDisplayOptions, preEnumerateTheories, internalDiagnosticMessages);
                if (typeName != null)
                {
                    controller.Find(typeName, false, this, discoveryOptions);
                }
                else
                {
                    controller.Find(false, this, discoveryOptions);
                }

                if (cancelled)
                {
                    // Synthesize the execution complete message, since we're not going to run at all
                    if (OnExecutionComplete != null)
                    {
                        OnExecutionComplete(ExecutionCompleteInfo.Empty);
                    }
                    return;
                }
            });
        }
예제 #2
0
        /// <summary>
        /// Starts running tests from a single type (if provided) or the whole assembly (if not). This call returns
        /// immediately, and status results are dispatched to the Info>s on this class. Callers can check <see cref="Status"/>
        /// to find out the current status.
        /// </summary>
        /// <param name="typeName">The (optional) type name of the single test class to run</param>
        /// <param name="diagnosticMessages">Set to <c>true</c> to enable diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        /// <param name="methodDisplay">Set to choose the default display name style for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="methodDisplayOptions">Set to choose the default display name style options for test methods.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="preEnumerateTheories">Set to <c>true</c> to pre-enumerate individual theory tests; set to <c>false</c> to use
        /// a single test case for the theory. By default, uses the value from the assembly configuration file. (This parameter is ignored
        /// for xUnit.net v1 tests.)</param>
        /// <param name="parallel">Set to <c>true</c> to run test collections in parallel; set to <c>false</c> to run them sequentially.
        /// By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="maxParallelThreads">Set to 0 to use unlimited threads; set to any other positive integer to limit to an exact number
        /// of threads. By default, uses the value from the assembly configuration file. (This parameter is ignored for xUnit.net v1 tests.)</param>
        /// <param name="internalDiagnosticMessages">Set to <c>true</c> to enable internal diagnostic messages; set to <c>false</c> to disable them.
        /// By default, uses the value from the assembly configuration file.</param>
        public void Start(string typeName                 = null,
                          bool?diagnosticMessages         = null,
                          TestMethodDisplay?methodDisplay = null,
                          TestMethodDisplayOptions?methodDisplayOptions = null,
                          bool?preEnumerateTheories       = null,
                          bool?parallel                   = null,
                          int?maxParallelThreads          = null,
                          bool?internalDiagnosticMessages = null)
        {
            lock (statusLock)
            {
                if (Status != AssemblyRunnerStatus.Idle)
                {
                    throw new InvalidOperationException("Calling Start is not valid when the current status is not idle.");
                }

                cancelled           = false;
                testCasesDiscovered = 0;
                testCasesToRun.Clear();
                discoveryCompleteEvent.Reset();
                executionCompleteEvent.Reset();
            }

            XunitWorkerThread.QueueUserWorkItem(() =>
            {
                var discoveryOptions = GetDiscoveryOptions(diagnosticMessages, methodDisplay, methodDisplayOptions, preEnumerateTheories, internalDiagnosticMessages);
                if (typeName != null)
                {
                    controller.Find(typeName, false, this, discoveryOptions);
                }
                else
                {
                    controller.Find(false, this, discoveryOptions);
                }

                discoveryCompleteEvent.WaitOne();
                if (cancelled)
                {
                    // Synthesize the execution complete message, since we're not going to run at all
                    if (OnExecutionComplete != null)
                    {
                        OnExecutionComplete(ExecutionCompleteInfo.Empty);
                    }
                    return;
                }

                var executionOptions = GetExecutionOptions(diagnosticMessages, parallel, maxParallelThreads, internalDiagnosticMessages);
                controller.RunTests(testCasesToRun, this, executionOptions);
                executionCompleteEvent.WaitOne();
            });
        }
예제 #3
0
        public void Start()
        {
            lock (statusLock)
            {
                if (Status != AssemblyRunnerStatus.Idle)
                {
                    throw new InvalidOperationException("Cannot start the runner");
                }

                testCasesToRun.Clear();
                discoveryCompleteEvent.Reset();
                executionCompleteEvent.Reset();
            }

            ExecutionXml = new XElement("assembly");

            Task.Factory.StartNew(() =>
            {
                var xmlCreationSink = new XmlCreationSinkDecorator(this);

                controller.Find(false, this, GetDiscoveryOptions());
                discoveryCompleteEvent.WaitOne();

                controller.RunTests(testCasesToRun, xmlCreationSink, GetExecutionOptions());
                executionCompleteEvent.WaitOne();

                ExecutionXml = xmlCreationSink.GetBuiltXml();
                OnExecutionComplete?.Invoke(ExecutionXml);
            });
        }
예제 #4
0
        private void DiscoverTests(TestOptions options, IFrontController frontController, IServiceProvider services)
        {
            var visitor = new DiscoveryVisitor((services.GetService(typeof(ITestSinkFactory)) as ITestSinkFactory)?.CreateDiscoverySink(services) ?? new DefaultTestDiscoverySink());

            frontController.Find(true, visitor, options);
            visitor.Finished.WaitOne();
        }