Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FrontControllerFindSettings"/> class.
 /// </summary>
 /// <param name="options">The options used during execution</param>
 /// <param name="serializedTestCases">The test cases to be run</param>
 public FrontControllerRunSettings(
     _ITestFrameworkExecutionOptions options,
     IEnumerable <string> serializedTestCases)
 {
     Options             = Guard.ArgumentNotNull(nameof(options), options);
     SerializedTestCases = Guard.ArgumentNotNull(nameof(serializedTestCases), serializedTestCases);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FrontControllerFindSettings"/> class.
 /// </summary>
 /// <param name="options">The options used during execution</param>
 /// <param name="serializedTestCases">The test cases to be run</param>
 public FrontControllerRunSettings(
     _ITestFrameworkExecutionOptions options,
     IReadOnlyCollection <string> serializedTestCases)
 {
     Options             = Guard.ArgumentNotNull(options);
     SerializedTestCases = Guard.ArgumentNotNull(serializedTestCases);
 }
        /// <summary>
        /// Sets the culture to use for running tests. <c>null</c> uses the default OS culture;
        /// <see cref="string.Empty"/> uses the invariant culture; any other value passes the
        /// provided value to <see cref="CultureInfo(string)"/> and uses the resulting object
        /// with <see cref="CultureInfo.DefaultThreadCurrentCulture"/> and
        /// <see cref="CultureInfo.DefaultThreadCurrentUICulture"/>.
        /// </summary>
        public static void SetCulture(
            this _ITestFrameworkExecutionOptions executionOptions,
            string?culture)
        {
            Guard.ArgumentNotNull(executionOptions);

            executionOptions.SetValue(TestOptionsNames.Execution.Culture, culture);
        }
        /// <summary>
        /// Sets a flag that determines whether internal diagnostic messages will be emitted.
        /// </summary>
        public static void SetInternalDiagnosticMessages(
            this _ITestFrameworkExecutionOptions executionOptions,
            bool?value)
        {
            Guard.ArgumentNotNull(executionOptions);

            executionOptions.SetValue(TestOptionsNames.Execution.InternalDiagnosticMessages, value);
        }
        /// <summary>
        /// Sets a flag that determines whether xUnit.net stop testing when a test fails.
        /// </summary>
        public static void SetStopOnTestFail(
            this _ITestFrameworkExecutionOptions executionOptions,
            bool?value)
        {
            Guard.ArgumentNotNull(executionOptions);

            executionOptions.SetValue(TestOptionsNames.Execution.StopOnFail, value);
        }
        /// <summary>
        /// Sets a flag to disable parallelization.
        /// </summary>
        public static void SetDisableParallelization(
            this _ITestFrameworkExecutionOptions executionOptions,
            bool?value)
        {
            Guard.ArgumentNotNull(executionOptions);

            executionOptions.SetValue(TestOptionsNames.Execution.DisableParallelization, value);
        }
        /// <summary>
        /// Sets the maximum number of threads to use when running tests in parallel.
        /// If set to 0 (the default value), does not limit the number of threads.
        /// </summary>
        public static void SetMaxParallelThreads(
            this _ITestFrameworkExecutionOptions executionOptions,
            int?value)
        {
            Guard.ArgumentNotNull(executionOptions);

            executionOptions.SetValue(TestOptionsNames.Execution.MaxParallelThreads, value);
        }
        /// <summary>
        /// Sets a flag that determines whether xUnit.net should report test results synchronously.
        /// </summary>
        public static void SetSynchronousMessageReporting(
            this _ITestFrameworkExecutionOptions executionOptions,
            bool?value)
        {
            Guard.ArgumentNotNull(executionOptions);

            executionOptions.SetValue(TestOptionsNames.Execution.SynchronousMessageReporting, value);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="XunitTestAssemblyRunnerContext"/> class.
 /// </summary>
 public XunitTestAssemblyRunnerContext(
     _ITestAssembly testAssembly,
     IReadOnlyCollection <IXunitTestCase> testCases,
     _IMessageSink executionMessageSink,
     _ITestFrameworkExecutionOptions executionOptions) :
     base(testAssembly, testCases, executionMessageSink, executionOptions)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XunitTestAssemblyRunner"/> class.
 /// </summary>
 /// <param name="testAssembly">The assembly that contains the tests to be run.</param>
 /// <param name="testCases">The test cases to be run.</param>
 /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param>
 /// <param name="executionMessageSink">The message sink to report run status to.</param>
 /// <param name="executionOptions">The user's requested execution options.</param>
 public XunitTestAssemblyRunner(
     _ITestAssembly testAssembly,
     IEnumerable <IXunitTestCase> testCases,
     _IMessageSink diagnosticMessageSink,
     _IMessageSink executionMessageSink,
     _ITestFrameworkExecutionOptions executionOptions)
     : base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions)
 {
 }
        void AddExecutionOptions(
            string?assemblyFilename,
            _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.NotNull("Attempted to log messages for an XunitProjectAssembly without first setting AssemblyFilename", assemblyFilename);

            using (ReaderWriterLockWrapper.WriteLock())
                executionOptionsByAssembly[assemblyFilename] = executionOptions;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FrontControllerFindSettings"/> class.
 /// </summary>
 /// <param name="discoveryOptions">The options used during discovery</param>
 /// <param name="executionOptions">The options used during execution</param>
 /// <param name="filters">The optional filters (when not provided, finds all tests)</param>
 public FrontControllerFindAndRunSettings(
     _ITestFrameworkDiscoveryOptions discoveryOptions,
     _ITestFrameworkExecutionOptions executionOptions,
     XunitFilters?filters = null)
 {
     DiscoveryOptions = Guard.ArgumentNotNull(nameof(discoveryOptions), discoveryOptions);
     ExecutionOptions = Guard.ArgumentNotNull(nameof(executionOptions), executionOptions);
     Filters          = filters ?? new XunitFilters();
 }
Exemplo n.º 13
0
 TestableXunitTestAssemblyRunner(
     _ITestAssembly testAssembly,
     IEnumerable <IXunitTestCase> testCases,
     List <_MessageSinkMessage> diagnosticMessages,
     _IMessageSink executionMessageSink,
     _ITestFrameworkExecutionOptions executionOptions)
     : base(testAssembly, testCases, SpyMessageSink.Create(messages: diagnosticMessages), executionMessageSink, executionOptions)
 {
     DiagnosticMessages = diagnosticMessages;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestAssemblyRunnerContext{TTestCase}"/> class.
 /// </summary>
 public TestAssemblyRunnerContext(
     _ITestAssembly testAssembly,
     IReadOnlyCollection <TTestCase> testCases,
     _IMessageSink executionMessageSink,
     _ITestFrameworkExecutionOptions executionOptions)
 {
     TestAssembly         = Guard.ArgumentNotNull(testAssembly);
     TestCases            = Guard.ArgumentNotNull(testCases);
     ExecutionMessageSink = Guard.ArgumentNotNull(executionMessageSink);
     ExecutionOptions     = Guard.ArgumentNotNull(executionOptions);
 }
Exemplo n.º 15
0
 TestableXunitTestAssemblyRunner(
     _ITestAssembly testAssembly,
     IReadOnlyCollection <IXunitTestCase> testCases,
     _IMessageSink executionMessageSink,
     _ITestFrameworkExecutionOptions executionOptions)
 {
     this.testAssembly         = testAssembly;
     this.testCases            = testCases;
     this.executionMessageSink = executionMessageSink;
     this.executionOptions     = executionOptions;
 }
        /// <summary>
        /// Gets the maximum number of threads to use when running tests in parallel. If set to 0 (or not set),
        /// the value of <see cref="Environment.ProcessorCount"/> is used; if set to a value less
        /// than 0, does not limit the number of threads.
        /// </summary>
        public static int GetMaxParallelThreadsOrDefault(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            var result = executionOptions.GetMaxParallelThreads();

            if (result == null || result == 0)
            {
                return(Environment.ProcessorCount);
            }

            return(result.GetValueOrDefault());
        }
Exemplo n.º 17
0
        /// <summary>
        /// Starts the process of running selected tests in the assembly.
        /// </summary>
        /// <param name="executor">The test framework executor.</param>
        /// <param name="testCases">The test cases to run.</param>
        /// <param name="executionMessageSink">The message sink to report results back to.</param>
        /// <param name="executionOptions">The options to be used during test execution.</param>
        public static void RunTests(
            this _ITestFrameworkExecutor executor,
            IEnumerable <_TestCaseDiscovered> testCases,
            _IMessageSink executionMessageSink,
            _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(nameof(executor), executor);
            Guard.ArgumentNotNull(nameof(testCases), testCases);
            Guard.ArgumentNotNull(nameof(executionMessageSink), executionMessageSink);
            Guard.ArgumentNotNull(nameof(executionOptions), executionOptions);

            executor.RunTests(testCases.Select(tc => tc.Serialization), executionMessageSink, executionOptions);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestAssemblyRunner{TTestCase}"/> class.
        /// </summary>
        /// <param name="testAssembly">The assembly that contains the tests to be run.</param>
        /// <param name="testCases">The test cases to be run.</param>
        /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param>
        /// <param name="executionMessageSink">The message sink to report run status to.</param>
        /// <param name="executionOptions">The user's requested execution options.</param>
        protected TestAssemblyRunner(
            _ITestAssembly testAssembly,
            IEnumerable <TTestCase> testCases,
            _IMessageSink diagnosticMessageSink,
            _IMessageSink executionMessageSink,
            _ITestFrameworkExecutionOptions executionOptions)
        {
            this.testAssembly          = Guard.ArgumentNotNull(nameof(testAssembly), testAssembly);
            this.testCases             = Guard.ArgumentNotNull(nameof(testCases), testCases);
            this.diagnosticMessageSink = Guard.ArgumentNotNull(nameof(diagnosticMessageSink), diagnosticMessageSink);
            this.executionMessageSink  = Guard.ArgumentNotNull(nameof(executionMessageSink), executionMessageSink);
            this.executionOptions      = Guard.ArgumentNotNull(nameof(executionOptions), executionOptions);

            testCaseOrderer = new DefaultTestCaseOrderer(DiagnosticMessageSink);
        }
Exemplo n.º 19
0
        TestableTestAssemblyRunner(
            _ITestAssembly testAssembly,
            IEnumerable <_ITestCase> testCases,
            List <_MessageSinkMessage> diagnosticMessages,
            _IMessageSink executionMessageSink,
            _ITestFrameworkExecutionOptions executionOptions,
            RunSummary result,
            bool cancelInRunTestCollectionAsync)
            : base(testAssembly, testCases, SpyMessageSink.Create(messages: diagnosticMessages), executionMessageSink, executionOptions)
        {
            DiagnosticMessages = diagnosticMessages;

            this.result = result;
            this.cancelInRunTestCollectionAsync = cancelInRunTestCollectionAsync;
        }
        /// <summary>
        /// Gets a flag to disable parallelization.
        /// </summary>
        public static bool?GetDisableParallelization(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetValue <bool?>(TestOptionsNames.Execution.DisableParallelization));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Gets a flag to stop testing on test failure.
        /// </summary>
        public static bool?StopOnTestFail(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(nameof(executionOptions), executionOptions);

            return(executionOptions.GetValue <bool?>(TestOptionsNames.Execution.StopOnFail));
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets a flag to stop testing on test failure. If the flag is not present, returns the
        /// default value (<c>false</c>).
        /// </summary>
        public static bool StopOnTestFailOrDefault(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(nameof(executionOptions), executionOptions);

            return(executionOptions.StopOnTestFail() ?? false);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Adapts v3 framework execution options into v2 framework execution options.
 /// </summary>
 public static ITestFrameworkExecutionOptions Adapt(_ITestFrameworkExecutionOptions options) =>
 new Xunit2Options(options);
        // Read/write methods for execution options

        /// <summary>
        /// Gets the culture to use for running tests. <c>null</c> uses the default OS culture;
        /// <see cref="string.Empty"/> uses the invariant culture; any other value passes the
        /// provided value to <see cref="CultureInfo(string)"/> and uses the resulting object
        /// with <see cref="CultureInfo.DefaultThreadCurrentCulture"/> and
        /// <see cref="CultureInfo.DefaultThreadCurrentUICulture"/>.
        /// </summary>
        public static string?GetCulture(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetValue <string?>(TestOptionsNames.Execution.Culture));
        }
        /// <summary>
        /// Gets a flag that determines whether xUnit.net should report test results synchronously.
        /// If the flag is not set, returns the default value (<c>false</c>).
        /// </summary>
        public static bool GetSynchronousMessageReportingOrDefault(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetSynchronousMessageReporting() ?? false);
        }
        /// <summary>
        /// Gets a flag that determines whether xUnit.net should report test results synchronously.
        /// </summary>
        public static bool?GetSynchronousMessageReporting(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetValue <bool?>(TestOptionsNames.Execution.SynchronousMessageReporting));
        }
        /// <summary>
        /// Gets the maximum number of threads to use when running tests in parallel.
        /// </summary>
        public static int?GetMaxParallelThreads(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetValue <int?>(TestOptionsNames.Execution.MaxParallelThreads));
        }
        /// <summary>
        /// Gets a flag to disable parallelization. If the flag is not present, returns the
        /// default value (<c>false</c>).
        /// </summary>
        public static bool GetDisableParallelizationOrDefault(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetDisableParallelization() ?? false);
        }
        /// <summary>
        /// Gets a flag that determines whether internal diagnostic messages will be emitted.
        /// </summary>
        public static bool?GetInternalDiagnosticMessages(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetValue <bool?>(TestOptionsNames.Execution.InternalDiagnosticMessages));
        }
        /// <summary>
        /// Gets a flag that determines whether internal diagnostic messages will be emitted. If the flag is not
        /// present, returns the default value (<c>false</c>).
        /// </summary>
        public static bool GetInternalDiagnosticMessagesOrDefault(this _ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull(executionOptions);

            return(executionOptions.GetInternalDiagnosticMessages() ?? false);
        }