示例#1
0
        private async Task OnExecuteAsync(CommandLineApplication app)
        {
            EnsureAllTestsRegistered();

            var tests = TestFinder.FindTestNames(Test);

            Log.Information("Begining {NumTests} tests.", tests.Count);

            // Exceptions shouldn't escape this in normal circumstances.
            var executor = await Execute(tests);

            var totalRan      = executor.TestsRun;
            var totalFailed   = executor.TestsFailed;
            var exceptionList = executor.Exceptions;

            Log.Information("-----------------------------------------");
            Log.Information("Test Results:");
            Log.Information($"Tests Run: {totalRan}");
            Log.Information($"Tests Succesful: {totalRan - totalFailed}");
            Log.Information($"Tests Failed: {totalFailed}");
            Log.Information("-----------------------------------------");

            if (totalFailed > 0)
            {
                throw new AggregateException(exceptionList);
            }
        }
示例#2
0
        private async Task OnExecuteAsync(CommandLineApplication app)
        {
            if (ConnectionInfo.Endpoint.Equals("localhost") && Parallel > 1)
            {
                throw new ArgumentException("Local and Parallel execution are incompatible");
            }

            if (Interactive && Parallel > 1)
            {
                throw new ArgumentException("Interactive mode and Parallel execution are incompatible");
            }

            if (Parallel < 1)
            {
                throw new ArgumentException("Parallel must be greater than 1.");
            }

            EnsureAllTestsRegistered();

            var tests = TestFinder.FindTestNames(Test);

            var batchSize = tests.Count() / Parallel;

            var batches = new List <List <string> >();

            for (var i = 0; i < Parallel; i++)
            {
                batches.Add(tests.Skip(i * batchSize).Take(batchSize).ToList());
            }

            Log.Information("Begining {Parallel} parallel test runs with batches : {@Batches}", Parallel, batches);

            // Exceptions shouldn't escape this in normal circumstances.
            var executors = await Task.WhenAll(batches.Select(b => Execute(b)).ToList());

            var totalRan      = executors.Select(ex => ex.TestsRun).Sum();
            var totalFailed   = executors.Select(ex => ex.TestsFailed).Sum();
            var exceptionList = executors.SelectMany(ex => ex.Exceptions);

            Log.Information("-----------------------------------------");
            Log.Information("Test Results:");
            Log.Information($"Tests Run: {totalRan}");
            Log.Information($"Tests Succesful: {totalRan - totalFailed}");
            Log.Information($"Tests Failed: {totalFailed}");
            Log.Information("-----------------------------------------");

            if (totalFailed > 0)
            {
                throw new AggregateException(exceptionList);
            }
        }