Beispiel #1
0
        TestSuite GetTestSuite()
        {
            var assembly = GetType().GetTypeInfo().Assembly;
            var builder  = new NUnitLiteTestAssemblyBuilder();

            return(builder.Build(assembly, new Dictionary <string, object>()));
        }
Beispiel #2
0
        public override void Run(IList <TestAssemblyInfo> testAssemblies)
        {
            if (testAssemblies == null)
            {
                throw new ArgumentNullException(nameof(testAssemblies));
            }

            var builder   = new NUnitLiteTestAssemblyBuilder();
            var runner    = new NUnitLiteTestAssemblyRunner(builder);
            var testSuite = new TestSuite(global::Android.App.Application.Context.PackageName);

            results = new TestSuiteResult(testSuite);

            foreach (TestAssemblyInfo assemblyInfo in testAssemblies)
            {
                if (assemblyInfo == null || assemblyInfo.Assembly == null)
                {
                    continue;
                }

                if (!runner.Load(assemblyInfo.Assembly, builderSettings))
                {
                    OnWarning($"Failed to load tests from assembly '{assemblyInfo.Assembly}");
                    continue;
                }
                if (runner.LoadedTest is NUnitTest tests)
                {
                    testSuite.Add(tests);
                }

                // Messy API. .Run returns ITestResult which is, in reality, an instance of TestResult since that's
                // what WorkItem returns and we need an instance of TestResult to add it to TestSuiteResult. So, cast
                // the return to TestResult and hope for the best.
                ITestResult result = null;
                try {
                    OnAssemblyStart(assemblyInfo.Assembly);
                    result = runner.Run(this, Filter);
                } finally {
                    OnAssemblyFinish(assemblyInfo.Assembly);
                }

                if (result == null)
                {
                    continue;
                }

                var testResult = result as TestResult;
                if (testResult == null)
                {
                    throw new InvalidOperationException($"Unexpected test result type '{result.GetType ()}'");
                }
                results.AddResult(testResult);
            }

            LogFailureSummary();
        }
Beispiel #3
0
        public IList <TestSuite> FindTests()
        {
            testSuites.Clear();
            ITestAssemblyBuilder testSuiteBuilder = new NUnitLiteTestAssemblyBuilder();
            TestSuite            testSuite;

            foreach (Assembly assembly in assembliesToTest)
            {
                testSuite = testSuiteBuilder.Build(assembly, new Hashtable());
                if (testSuite != null)
                {
                    testSuites.Add(testSuite);
                }
            }

            return(testSuites);
        }
Beispiel #4
0
        internal static void Run(string title, Stream outputStream)
        {
            var suite   = new TestSuite(title);
            var builder = new NUnitLiteTestAssemblyBuilder();

            suite.Add(builder.Build(System.Reflection.Assembly.GetExecutingAssembly(), new Dictionary <string, object>()));

            var testExecutionContext = TestExecutionContext.CurrentContext;

            testExecutionContext.WorkDirectory = Environment.CurrentDirectory;

            var workItem = suite.CreateWorkItem(TestFilter.Empty);

            workItem.Execute(testExecutionContext);

            var testWriter = new NUnitLite.Runner.NUnit2XmlOutputWriter(DateTime.Now);

            using (var writer = new StreamWriter(outputStream))
            {
                testWriter.WriteResultFile(workItem.Result, writer);
            }
        }
        public override void Run(IList <TestAssemblyInfo> testAssemblies)
        {
            if (testAssemblies == null)
            {
                throw new ArgumentNullException(nameof(testAssemblies));
            }

            if (AssemblyFilters == null || AssemblyFilters.Count == 0)
            {
                runAssemblyByDefault = true;
            }
            else
            {
                runAssemblyByDefault = AssemblyFilters.Values.Any(v => !v);
            }

            var builder   = new NUnitLiteTestAssemblyBuilder();
            var runner    = new NUnitLiteTestAssemblyRunner(builder, new FinallyDelegate());
            var testSuite = new TestSuite(NSBundle.MainBundle.BundleIdentifier);

            results = new TestSuiteResult(testSuite);

            TotalTests = 0;
            foreach (TestAssemblyInfo assemblyInfo in testAssemblies)
            {
                if (assemblyInfo == null || assemblyInfo.Assembly == null || !ShouldRunAssembly(assemblyInfo))
                {
                    continue;
                }

                if (!runner.Load(assemblyInfo.Assembly, builderSettings))
                {
                    OnWarning($"Failed to load tests from assembly '{assemblyInfo.Assembly}");
                    continue;
                }
                if (runner.LoadedTest is NUnitTest tests)
                {
                    TotalTests += tests.TestCaseCount;
                    testSuite.Add(tests);
                }

                // Messy API. .Run returns ITestResult which is, in reality, an instance of TestResult since that's
                // what WorkItem returns and we need an instance of TestResult to add it to TestSuiteResult. So, cast
                // the return to TestResult and hope for the best.
                ITestResult result = null;
                try {
                    OnAssemblyStart(assemblyInfo.Assembly);
                    result = runner.Run(this, Filter);
                } finally {
                    OnAssemblyFinish(assemblyInfo.Assembly);
                }

                if (result == null)
                {
                    continue;
                }

                var testResult = result as TestResult;
                if (testResult == null)
                {
                    throw new InvalidOperationException($"Unexpected test result type '{result.GetType ()}'");
                }
                results.AddResult(testResult);
            }

            // NUnitLite doesn't report filtered tests at all, but we can calculate here
            FilteredTests = TotalTests - ExecutedTests;
            LogFailureSummary();
        }