Exemple #1
0
        // TODO implement launching in a seperate App Domain
        private RunnerResult ExecuteInAppDomain(NUnitTestData test)
        {
            // spawn new domain in specified directory
            AppDomainSetup domSetup = new AppDomainSetup();

            domSetup.ApplicationBase   = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            domSetup.ConfigurationFile = Project.GetFullPath(test.AppConfigFile);
            domSetup.ApplicationName   = "NAnt Remote Domain";
#if NET_4_0
            PermissionSet domainPermSet = new PermissionSet(PermissionState.Unrestricted);
            AppDomain     newDomain     = AppDomain.CreateDomain(domSetup.ApplicationName, AppDomain.CurrentDomain.Evidence,
                                                                 domSetup, domainPermSet);
#else
            AppDomain newDomain = AppDomain.CreateDomain(domSetup.ApplicationName, AppDomain.CurrentDomain.Evidence, domSetup);
#endif
            // instantiate subclassed test runner in new domain
            Type         runnerType = typeof(RemoteNUnitTestRunner);
            ObjectHandle oh         = newDomain.CreateInstance(
                runnerType.Assembly.FullName,
                runnerType.FullName,
                false, 0, null,
                new object[] { test },
                null, null, null
                );
            RemoteNUnitTestRunner runner = (RemoteNUnitTestRunner)(oh.Unwrap());
            Log(Level.Info, "Running '{0}'.", test.Class);

            runner.Run(string.Empty, Verbose);
            return(runner.ResultCode);
        }
        public NUnitTestRunner(NUnitTestData testData)
        {
            _nunittest = testData;
            string nunitsuite = testData.Class + "," + testData.Assembly;

            _suite         = GetSuite(nunitsuite);
            testData.Suite = _suite;
        }
 /// <summary>
 /// Returns the output file or null if does not use a file.
 /// </summary>
 protected FileInfo GetOutput(FormatterData formatterData, NUnitTestData test)
 {
     if (formatterData.UseFile)
     {
         string filename    = test.OutFile + formatterData.Extension;
         string absFilename = Path.Combine(test.ToDir, filename);
         return(new FileInfo(absFilename));
     }
     return(null);
 }
Exemple #4
0
        private void ExecuteTest(NUnitTest test)
        {
            // Set Defaults
            RunnerResult result = RunnerResult.Success;

            if (test.ToDir == null)
            {
                test.ToDir = Project.BaseDirectory;
            }
            if (test.OutFile == null)
            {
                test.OutFile = "TEST-" + test.Class;
            }

            NUnitTestData testData = test.GetTestData();

            foreach (FormatterElement element in FormatterElements)
            {
                testData.Formatters.Add(element.Data);
            }

            if (testData.Fork == true)
            {
                result = ExecuteInAppDomain(testData);
            }
            else
            {
                result = ExecuteInProc(testData);
            }

            // Handle return code:
            // If there is an error/failure and that it should halt, stop
            // everything otherwise just log a statement.
            bool errorOccurred   = (result == RunnerResult.Errors);
            bool failureOccurred = (result != RunnerResult.Success);

            if ((errorOccurred && test.HaltOnError) || (failureOccurred && test.HaltOnFailure))
            {
                // Only thrown if this test should halt as soon as the first
                // error/failure is detected.  In most cases all tests will
                // be run to get a full list of problems.
                throw new BuildException("Test " + testData.Class + " Failed", Location);
            }

            // Used for reporting the final result from the task.
            if (errorOccurred)
            {
                _errorsPresent = true;
            }
            if (failureOccurred)
            {
                _failuresPresent = true;
            }
        }
        /// <summary>
        /// Creates the formatters to be used when running this test.
        /// </summary>
        protected void CreateFormatters(NUnitTestData testData, string logPrefix, bool verbose)
        {
            // Now add the specified formatters
            foreach (FormatterData formatterData in testData.Formatters)
            {
                // determine file
                FileInfo         outFile   = GetOutput(formatterData, testData);
                IResultFormatter formatter = CreateFormatter(formatterData.Type, outFile);
                Formatters.Add(formatter);
            }
            // Add default formatter
            // The Log formatter is special in that it always writes to the
            // Log class rather than the TextWriter set in SetOutput().
            // HACK!
            LogFormatter logFormatter = new LogFormatter(logPrefix, verbose);

            Formatters.Add(logFormatter);
        }
Exemple #6
0
        private RunnerResult ExecuteInProc(NUnitTestData test)
        {
            try {
                NUnitTestRunner runner = new NUnitTestRunner(test);

                if (runner.NeedsRunning())
                {
                    Log(Level.Info, "Running '{0}'.", test.Class);
                    runner.Run(string.Empty, Verbose);
                }
                else
                {
                    Log(Level.Info, "Skipping '{0}' because tests haven't changed.", test.Class);
                }
                return(runner.ResultCode);
            } catch (Exception ex) {
                throw new BuildException("Error running unit test.", Location, ex);
            }
        }
 public RemoteNUnitTestRunner(NUnitTestData testData)
 {
     _runner = new NUnitTestRunner(testData);
 }