示例#1
1
 private static TestResult RunTests( string assemFile, ConsoleListener l )
 {
     TestPackage testPackage = new TestPackage( assemFile );
     RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
     remoteTestRunner.Load( testPackage );
     return remoteTestRunner.Run( l, TestFilter.Empty, false, LoggingThreshold.Debug );
 }
示例#2
0
 public SessionResults RunAssembly(Assembly assembly)
 {
     var remoteTestRunner = new RemoteTestRunner(0);
     var package = SetupTestPackager(assembly);
     remoteTestRunner.Load(package);
     var listener = new GilesNUnitEventListener();
     remoteTestRunner.Run(listener);
     return listener.SessionResults;
 }
示例#3
0
        public void Run()
        {
            if (!File.Exists(_path)) return;
            var testPackage = new TestPackage(_path);
            var remoteTestRunner = new RemoteTestRunner();
            if (!remoteTestRunner.Load(testPackage)) return;

            var testResult = remoteTestRunner.Run(_eventListener, TestFilter.Empty, false, LoggingThreshold.Error);
        }
示例#4
0
 public Result Run(string file, Result compileResult)
 {
     RemoteTestRunner runner = new RemoteTestRunner();
     TestPackage package = new TestPackage("Test");
     package.Assemblies.Add(file);
     if (runner.Load(package))
     {
         TestResult result = runner.Run(new TestListner(compileResult), new TestFilter(), false, LoggingThreshold.All);
     }
     return compileResult;
 }
示例#5
0
 public SessionResults RunAssembly(Assembly assembly, IEnumerable<string> filters)
 {
     this.filters = filters;
     var remoteTestRunner = new RemoteTestRunner(0);
     var package = SetupTestPackager(assembly);
     remoteTestRunner.Load(package);
     var listener = new GilesNUnitEventListener();
     if (filters.Count() == 0)
         remoteTestRunner.Run(listener);
     else
         remoteTestRunner.Run(listener, GetFilters());
     return listener.SessionResults;
 }
示例#6
0
		public TestResult Run (EventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies)
		{
			InitSupportAssemblies (supportAssemblies);
			
			if (filter == null)
				filter = TestFilter.Empty;
			
			RemoteTestRunner tr = new RemoteTestRunner ();
			TestPackage package = new TestPackage (path);
			if (!string.IsNullOrEmpty (suiteName))
				package.TestName = suiteName;
			tr.Load (package);
			return tr.Run (listener, filter, false, LoggingThreshold.All);
		}
示例#7
0
        private TestResult RunTestsInAssemblies(IList assemblies, ITestFilter testfilter)
        {
            // Note: in order for nunit to unload assembly (not lock it)
             // we are using a modified version of nunit.core.dll (and the dependent nunit.interfaces.dll)
             // if the nunit dlls are updated this is what needs to be changed:
             //      in TestAssemblyBuilder class in Load method,
             //      change "assembly = Assembly.Load(assemblyName);"
             //      to "assembly = Assembly.Load(File.ReadAllBytes(path));"
             TestPackage theTestPackage = new TestPackage("All Dlls", assemblies);
             theTestPackage.Settings.Add("UseThreadedRunner", false);
             theTestPackage.Settings.Add("DomainUsage", DomainUsage.None);
             RemoteTestRunner testRunner = new RemoteTestRunner();
             testRunner.Load(theTestPackage);
             TestResult testResult = testRunner.Run(NullListener.NULL, testfilter, false, LoggingThreshold.Off);

             // Dispose
             testRunner.Unload();
             testRunner.Dispose();
             return testResult;
        }
示例#8
0
文件: ConsoleUi.cs 项目: nobled/mono
		private static TestRunner MakeRunnerFromCommandLine( ConsoleOptions options )
		{
			TestPackage package;
			ConsoleOptions.DomainUsage domainUsage = ConsoleOptions.DomainUsage.Default;

			if (options.IsTestProject)
			{
				NUnitProject project = NUnitProject.LoadProject((string)options.Parameters[0]);
				string configName = options.config;
				if (configName != null)
					project.SetActiveConfig(configName);

				package = project.ActiveConfig.MakeTestPackage();
				package.TestName = options.fixture;

				domainUsage = ConsoleOptions.DomainUsage.Single;
			}
			else if (options.Parameters.Count == 1)
			{
				package = new TestPackage((string)options.Parameters[0]);
				domainUsage = ConsoleOptions.DomainUsage.Single;
			}
			else
			{
				package = new TestPackage("UNNAMED", options.Parameters);
				domainUsage = ConsoleOptions.DomainUsage.Multiple;
			}

			if (options.domain != ConsoleOptions.DomainUsage.Default)
				domainUsage = options.domain;
                    
			TestRunner testRunner = null;
				
			switch( domainUsage )
			{
				case ConsoleOptions.DomainUsage.None:
					testRunner = new NUnit.Core.RemoteTestRunner();
					// Make sure that addins are available
					CoreExtensions.Host.AddinRegistry = Services.AddinRegistry;
					break;

				case ConsoleOptions.DomainUsage.Single:
					testRunner = new TestDomain();
					break;

				case ConsoleOptions.DomainUsage.Multiple:
					testRunner = new MultipleTestDomainRunner();
					break;
			}

			package.TestName = options.fixture;
			package.Settings["ShadowCopyFiles"] = !options.noshadow;
			package.Settings["UseThreadedRunner"] = !options.nothread;
			testRunner.Load( package );

			return testRunner;
		}
示例#9
0
        private UnitTester(string testAssembly)
        {
            var testPackage = new TestPackage(Path.GetFileNameWithoutExtension(testAssembly));
            testPackage.Assemblies.Add(testAssembly);

            // Create a new appdomain with the appropriate working directory.
            // This is required so that we don't accidentially load the wrong dependencies.
            var setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(testAssembly);
            domain = AppDomain.CreateDomain("TestDomain", null, setup);
            
            runner = RemoteTestRunner.CreateInstance(domain, 0);
            runner.Load(testPackage);
        }
示例#10
0
		public TestResult Run (EventListener listener, ITestFilter filter, string path, string suiteName, List<string> supportAssemblies, string testRunnerType, string testRunnerAssembly)
		{
			InitSupportAssemblies (supportAssemblies);
			
			if (filter == null)
				filter = TestFilter.Empty;

			TestRunner tr;
			if (!string.IsNullOrEmpty (testRunnerType)) {
				Type runnerType;
				if (string.IsNullOrEmpty (testRunnerAssembly))
					runnerType = Type.GetType (testRunnerType, true);
				else {
					var asm = Assembly.LoadFrom (testRunnerAssembly);
					runnerType = asm.GetType (testRunnerType);
				}
				tr = (TestRunner)Activator.CreateInstance (runnerType);
			} else
				tr = new RemoteTestRunner ();

			TestPackage package = new TestPackage (path);
			if (!string.IsNullOrEmpty (suiteName))
				package.TestName = suiteName;
			tr.Load (package);
			return tr.Run (listener, filter, false, LoggingThreshold.All);
		}
        public void generateAndRunVBObjectTests()
        {
            int i = 0;
            DirectoryInfo d = new DirectoryInfo(Directory.GetCurrentDirectory());
            while (true) {
                i++;
                if(i>=20){
                    throw new ApplicationException ("could not get a dir with name GeneratorTests");
                }
                d = d.Parent;
                if (d.Name == "GeneratorTests") {
                    break;
                }

            }

            string path = d.FullName + "\\VbObjectTestsTmp.cs";
            if (File.Exists(path)) {
                File.Delete(path);
            }

            File.Copy(d.FullName + "\\CSharpObjectTests.cs", path);
            string readText = File.ReadAllText(path);

            readText = readText.Replace("using CsModelObjects;", "using ModelLibVBGenCode.VbBusObjects;");
            readText = readText.Replace("using CsModelMappers;", "using ModelLibVBGenCode.VbBusObjects.DBMappers;");
            //readText = readText.Replace("DateTime hireDate=new", "dim hireDate as DateTime=new");

            readText = readText.Replace("namespace GeneratorTests {", "namespace GeneratorTests.VB {");
            readText = readText.Replace("public class CSharpObjectTests {", "public class VBObjectTests {");
            readText = readText.Replace("public void createCsRecords()", "public void createVbRecords()");
            readText = readText.Replace("[TestClass]", "[NUnit.Framework.TestFixture]");
            readText = readText.Replace("[TestMethod]", "[NUnit.Framework.Test]");
            readText = readText.Replace("using Microsoft.VisualStudio.TestTools.UnitTesting;", "using NUnit.Framework;");
            readText = readText.Replace("Assert.", "NUnit.Framework.Assert.");
            readText = readText.Replace("public static void MyClassInitialize(TestContext testContext)", "public static void MyClassInitialize()");
            readText = readText.Replace("[ClassInitialize()]", "[NUnit.Framework.SetUp]");
            readText = readText.Replace("[ClassCleanup()]", "[NUnit.Framework.TearDown]");
            readText = readText.Replace("//NUnit.Framework.NUnit.Framework.Assert.IsTrue(false)", "NUnit.Framework.Assert.IsTrue(false);");
            readText = readText.Replace("//DBUtils.Current().ConnString=",
                    "org.model.lib.db.DBUtils.Current().ConnString=\"" + DBUtils.Current().ConnString.Replace("\\", "\\\\") + "\";");

            readText = readText.Replace("EnumProjectType.EXTERNAL", "ModelLibVBGenCode.EnumProjectType.EXTERNAL");
            readText = readText.Replace("void testCSharp", "void testVBNet");

            File.WriteAllText(path, readText);

            CSharpCodeProvider provider = new CSharpCodeProvider();
            CompilerParameters cp = new CompilerParameters();

            // this line is here otherwise ModelLibVBGenCode is not returned
            // in call to this.GetType().Assembly.GetReferencedAssemblies
            ModelLibVBGenCode.VbBusObjects.Employee e = null;
            NUnit.Framework.Guard x = null; // note: DO NOT REMOVE!

            var assemblies = this.GetType().Assembly.GetReferencedAssemblies().ToList();
            var assemblyLocations =
                        assemblies.Select(a =>
                        Assembly.ReflectionOnlyLoad(a.FullName).Location);

            var lstAssemblyLocations = assemblyLocations.Where(a => !a.Contains("Microsoft.VisualStudio.QualityTools.UnitTestFramework")).ToList();
            //Assembly.ReflectionOnlyLoad("")
            cp.ReferencedAssemblies.AddRange(lstAssemblyLocations.ToArray());

            cp.GenerateInMemory = false;// True - memory generation, false - external file generation
            cp.GenerateExecutable = false;// True - exe file generation, false - dll file generation
            CompilerResults results = provider.CompileAssemblyFromSource(cp, readText);
            Assert.AreEqual(0, results.Errors.Count,
                    "There should be no compilation errors, first error was:" +
                    (results.Errors.Count>0 ? results.Errors[0].ErrorText : ""));

            CoreExtensions.Host.InitializeService();
            TestPackage package = new TestPackage(results.CompiledAssembly.Location);
            RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
            remoteTestRunner.Load(package);
            TestResult result = remoteTestRunner.Run(new NullListener(),
                                    TestFilter.Empty, false, LoggingThreshold.All);

            Assert.IsTrue(result.HasResults, " must have test results ");
            Assert.IsTrue(result.IsSuccess, "dynamic vb tests must return success ");
        }
示例#12
0
        private static TestRunner MakeRunnerFromCommandLine(ConsoleOptions options)
        {
            TestPackage package;

            ConsoleOptions.DomainUsage domainUsage = ConsoleOptions.DomainUsage.Default;

            if (options.IsTestProject)
            {
                NUnitProject project    = NUnitProject.LoadProject((string)options.Parameters[0]);
                string       configName = options.config;
                if (configName != null)
                {
                    project.SetActiveConfig(configName);
                }

                package          = project.ActiveConfig.MakeTestPackage();
                package.TestName = options.fixture;

                domainUsage = ConsoleOptions.DomainUsage.Single;
            }
            else if (options.Parameters.Count == 1)
            {
                package     = new TestPackage((string)options.Parameters[0]);
                domainUsage = ConsoleOptions.DomainUsage.Single;
            }
            else
            {
                package     = new TestPackage("UNNAMED", options.Parameters);
                domainUsage = ConsoleOptions.DomainUsage.Multiple;
            }

            if (options.domain != ConsoleOptions.DomainUsage.Default)
            {
                domainUsage = options.domain;
            }

            TestRunner testRunner = null;

            switch (domainUsage)
            {
            case ConsoleOptions.DomainUsage.None:
                testRunner = new NUnit.Core.RemoteTestRunner();
                // Make sure that addins are available
                CoreExtensions.Host.AddinRegistry = Services.AddinRegistry;
                break;

            case ConsoleOptions.DomainUsage.Single:
                testRunner = new TestDomain();
                break;

            case ConsoleOptions.DomainUsage.Multiple:
                testRunner = new MultipleTestDomainRunner();
                break;
            }

            package.TestName = options.fixture;
            package.Settings["ShadowCopyFiles"]   = !options.noshadow;
            package.Settings["UseThreadedRunner"] = !options.nothread;
            testRunner.Load(package);

            return(testRunner);
        }
        static void Main(string[] args)
        {
            try {

            CoreExtensions.Host.InitializeService();

            int port = int.Parse(args[1]);

            TSocket socket = new TSocket("localhost", port);

            TestInterface.Client client = new TestInterface.Client(new TBinaryProtocol(socket));

            socket.Open();

            TestPackage testPackage = new TestPackage(args[0]);
            RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
            remoteTestRunner.Load(testPackage);
            remoteTestRunner.Run(new OurEventListener(client), TestFilter.Empty, false, LoggingThreshold.All);
              }
              catch(Exception e) {
            System.Console.WriteLine(e.Message + "\n" + e.StackTrace);
              }
        }
示例#14
0
        public static int RunAllTests()
        {
            var executingAssembly = Assembly.GetExecutingAssembly();
            var assemblyFilename = executingAssembly.Location;

            var consoleOut = Console.Out;

            var testPackage =
                new TestPackage(assemblyFilename) {AutoBinPath = true};
            testPackage.Settings["ShadowCopyFiles"] = false;
            testPackage.Settings["UseThreadedRunner"] = false;

            var listener =
                new SledSharedEventListener {ConsoleOut = consoleOut};

            var testRunner = new RemoteTestRunner();
            testRunner.Load(testPackage);
            testRunner.Run(listener);

            if (listener.FailedTestCount == 0)
                consoleOut.WriteLine("Success: " + listener.TestCount + " test(s) passed.");

            return listener.FailedTestCount;
        }
示例#15
0
        /// <summary>
        /// This is a "manual" test runner for the NUnit tests.  I made this so I can easily
        /// debug the individual tests without having to attach the debugger to the NUnit GUI process, etc.
        /// </summary>
        /// <param name="args"></param>
        static void Main(String[] args)
        {
            Debug.WriteLine("TestRunner starting...");

            var path = Assembly.GetExecutingAssembly().Location;

            CoreExtensions.Host.InitializeService();
            using (var testRunner = new RemoteTestRunner())
            {
                var package = new TestPackage("NCraft.Test.exe", new List<string>() { path });
                testRunner.Load(package);

                testRunner.Run(new LoggingEventListener(), TestFilter.Empty);
            }

            Debug.WriteLine("TestRunner complete!");
        }