예제 #1
0
        public void Should_produce_xml()
        {
            var plugins = new List<Plugin>();
            var options = new RunOptions();
            plugins.Add(new Plugin(@"C:\Some\Path\Assembly.dll", "This.Is.Full.Type.Name.For.Class.Implementing.IAutoTestNetTestRunner"));
            plugins.Add(new Plugin(@"C:\Some\Path\Assembly.dll", "Some.Class.Name"));

            var runner1 = new RunnerOptions("nunit");
            runner1.AddCategories(new string[] { "SomeTestCategory", "SomeOtherTestCategory" });
            var assembly1 = new AssemblyOptions(@"C:\my\testassembly.dll");
            assembly1.HasBeenVerified(true);
            assembly1.AddTests(new string[] { "testassembly.class.test1", "testassembly.class.test2" });
            assembly1.AddMembers(new string[] { "testassembly.class2", "testassembly.class3" });
            assembly1.AddNamespaces(new string[] { "testassembly.somenamespace1", "testassembly.somenamespace2" });
            runner1.AddAssemblies(new AssemblyOptions[] { assembly1, new AssemblyOptions(@"C:\my\anothernunitassembly.dll") });
            options.AddTestRun(runner1);

            var runner2 = new RunnerOptions("another");
            runner2.AddAssembly(new AssemblyOptions(@"C:\my\other\testassembly.dll"));
            options.AddTestRun(runner2);
            
            var writer = new OptionsXmlWriter(plugins, options);
            var file = Path.GetTempFileName();
            writer.Write(file);

            var path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            var original = File.ReadAllText(file).Replace("\r\n", "\n");
            var generated = File.ReadAllText(Path.Combine(path, "TestOptionsCorrected.xml")).Replace("\r\n", "\n");
            Assert.That(original, Is.EqualTo(generated));
        }
        public void Parse()
        {
            if (!File.Exists(_file))
            {
                _plugins = null;
                return;
            }

            _options = new RunOptions();
            using (var reader = new XmlTextReader(_file))
            {
                while (reader.Read())
                {
                    if (reader.Name.Equals("plugin") && reader.NodeType != XmlNodeType.EndElement)
                        getPlugin(reader);
                    else if (reader.Name.Equals("runner"))
                        getRunner(reader);
                    else if (reader.Name.Equals("ignore_category") && reader.NodeType != XmlNodeType.EndElement)
                        getCategory(reader);
                    else if (reader.Name.Equals("test_assembly"))
                        getAssembly(reader);
                    else if (reader.Name.Equals("test") && reader.NodeType != XmlNodeType.EndElement)
                        getTest(reader);
                    else if (reader.Name.Equals("member") && reader.NodeType != XmlNodeType.EndElement)
                        getMember(reader);
                    else if (reader.Name.Equals("namespace") && reader.NodeType != XmlNodeType.EndElement)
                        getNamespace(reader);
                }
            }
            IsValid = true;
        }
예제 #3
0
 private static RunOptions getRunOptions()
 {
     var assembly = new AssemblyOptions(@"P:\projects\mooseprofiler.git\MMProfiler\main\x86\Debug\Test.Target.dll");
     var run = new RunnerOptions("NUnit");
     run.AddAssembly(assembly);     
     var optoins = new RunOptions();
     optoins.AddTestRun(run);
     return optoins;
 }
        public void Should_group_by_assembly()
        {
            var locator = MockRepository.GenerateMock<IAssemblyReader>();
            locator.Stub(x => x.GetTargetFramework("Assembly1")).Return(new Version(2, 0));
            locator.Stub(x => x.GetTargetFramework("Assembly2")).Return(new Version(4, 0));
            locator.Stub(x => x.GetTargetFramework("Assembly3")).Return(new Version(2, 0));
            locator.Stub(x => x.GetTargetFramework("Assembly4")).Return(new Version(2, 0));
            locator.Stub(x => x.GetTargetFramework("Assembly5")).Return(new Version(2, 0));
            locator.Stub(x => x.GetTargetFramework("Assembly6")).Return(new Version(4, 0));

            locator.Stub(x => x.GetPlatform("Assembly1")).Return(Platform.AnyCPU);
            locator.Stub(x => x.GetPlatform("Assembly2")).Return(Platform.AnyCPU);
            locator.Stub(x => x.GetPlatform("Assembly3")).Return(Platform.AnyCPU);
            locator.Stub(x => x.GetPlatform("Assembly4")).Return(Platform.AnyCPU);
            locator.Stub(x => x.GetPlatform("Assembly5")).Return(Platform.x86);
            locator.Stub(x => x.GetPlatform("Assembly6")).Return(Platform.x86);

            var options = new RunOptions();
            var runner = new RunnerOptions("NUnit");
            runner.AddAssemblies(new AssemblyOptions[] { new AssemblyOptions("Assembly1"), new AssemblyOptions("Assembly2") });
            options.AddTestRun(runner);
            runner = new RunnerOptions("NUnit");
            runner.AddAssemblies(new AssemblyOptions[] { new AssemblyOptions("Assembly3"), new AssemblyOptions("Assembly5") });
            options.AddTestRun(runner);
            runner = new RunnerOptions("XUnit");
            runner.AddAssemblies(new AssemblyOptions[] { new AssemblyOptions("Assembly4"), new AssemblyOptions("Assembly6") });
            options.AddTestRun(runner);

            var assembler = new TargetedRunAssembler(options, locator);
            var targeted = assembler.Assemble();

            Assert.That(targeted.Count(), Is.EqualTo(4));
            Assert.That(targeted.ElementAt(0).Platform, Is.EqualTo(Platform.AnyCPU));
            Assert.That(targeted.ElementAt(0).TargetFramework, Is.EqualTo(new Version(2, 0)));
            Assert.That(targeted.ElementAt(0).Runners.Count(), Is.EqualTo(2));
            Assert.That(targeted.ElementAt(0).Runners.Count(), Is.EqualTo(2));
            Assert.That(targeted.ElementAt(0).Runners.ElementAt(0).ID, Is.EqualTo("NUnit"));
            Assert.That(targeted.ElementAt(0).Runners.ElementAt(0).Assemblies.ElementAt(0).Assembly, Is.EqualTo("Assembly1"));
            Assert.That(targeted.ElementAt(0).Runners.ElementAt(0).Assemblies.ElementAt(1).Assembly, Is.EqualTo("Assembly3"));
            Assert.That(targeted.ElementAt(0).Runners.ElementAt(1).ID, Is.EqualTo("XUnit"));
            Assert.That(targeted.ElementAt(0).Runners.ElementAt(1).Assemblies.ElementAt(0).Assembly, Is.EqualTo("Assembly4"));
            Assert.That(targeted.ElementAt(1).Platform, Is.EqualTo(Platform.AnyCPU));
            Assert.That(targeted.ElementAt(1).TargetFramework, Is.EqualTo(new Version(4, 0)));
            Assert.That(targeted.ElementAt(1).Runners.ElementAt(0).ID, Is.EqualTo("NUnit"));
            Assert.That(targeted.ElementAt(1).Runners.ElementAt(0).Assemblies.ElementAt(0).Assembly, Is.EqualTo("Assembly2"));
            Assert.That(targeted.ElementAt(2).Platform, Is.EqualTo(Platform.x86));
            Assert.That(targeted.ElementAt(2).TargetFramework, Is.EqualTo(new Version(2, 0)));
            Assert.That(targeted.ElementAt(2).Runners.ElementAt(0).ID, Is.EqualTo("NUnit"));
            Assert.That(targeted.ElementAt(2).Runners.ElementAt(0).Assemblies.ElementAt(0).Assembly, Is.EqualTo("Assembly5"));
            Assert.That(targeted.ElementAt(3).Platform, Is.EqualTo(Platform.x86));
            Assert.That(targeted.ElementAt(3).TargetFramework, Is.EqualTo(new Version(4, 0)));
            Assert.That(targeted.ElementAt(3).Runners.ElementAt(0).ID, Is.EqualTo("XUnit"));
            Assert.That(targeted.ElementAt(3).Runners.ElementAt(0).Assemblies.ElementAt(0).Assembly, Is.EqualTo("Assembly6"));
        }
예제 #5
0
 public IEnumerable<TestResult> ProcessTestRuns(RunOptions options)
 {
     _results = new List<TestResult>();
     var workers = new List<Thread>();
     var testRuns = getTargetedRuns(options);
     foreach (var target in testRuns)
     {
         var process = new TestProcess(target, _feedback);
         if (_runInParallel)
             process.RunParallel();
         var thread = new Thread(new ThreadStart(process.Start));
         thread.Start();
         workers.Add(thread);
     }
     foreach (var worker in workers)
         worker.Join();
     return _results;
 }
        public IEnumerable<TestResult> ProcessTestRuns(RunOptions options)
        {
            _results = new List<TestResult>();
            var workers = new List<Thread>();
            var testRuns = getTargetedRuns(options);
            foreach (var target in testRuns)
            {
                var process = new TestProcess(target, _feedback);
				if (_processWrapper != null)
                    process.WrapTestProcessWith(_processWrapper);
                if (_compatabilityMode)
                    process.RunInCompatibilityMode();
                process.AbortWhen(_abortWhen);
                var thread = new Thread(new ThreadStart(process.Start));
                thread.Start();
                workers.Add(thread);
            }
            foreach (var worker in workers)
                worker.Join();
            return _results;
        }
예제 #7
0
 public int StartPaused(RunOptions options, TestRunner runner)
 {
     var currentPath = Environment.CurrentDirectory;
     try
     {
         Environment.CurrentDirectory = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);
         using (var assembly = Reflect.On(options.TestRuns.ElementAt(0).Assemblies.ElementAt(0).Assembly))
         {
             _version = assembly.GetTargetFramework();
         }
         //var wrapper = getWrapper(options, runner);
         var inputFile = Path.GetTempFileName();
         var outputFile = Path.GetTempFileName();
         var writer = new OptionsXmlWriter(new Plugin[] {}, options);
         writer.Write(inputFile);
         AutoTest.Core.DebugLog.Debug.WriteDebug("About to debug:");
         AutoTest.Core.DebugLog.Debug.WriteDebug(File.ReadAllText(inputFile));
         var arguments = string.Format("--input=\"{0}\" --output=\"{1}\" --startsuspended --silent", inputFile, outputFile);
         var exe = new TestProcessSelector().Get(options.TestRuns.ElementAt(0).Assemblies.ElementAt(0).Assembly);
         AutoTest.Core.DebugLog.Debug.WriteDebug("Running: " + exe + " " + arguments);
         _process = new Process();
         _process.StartInfo = new ProcessStartInfo(exe, arguments);
         _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
         _process.StartInfo.RedirectStandardInput = true;
         _process.StartInfo.UseShellExecute = false;
         _process.StartInfo.CreateNoWindow = true;
         _process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
         _process.Start();
         return _process.Id;
     }
     catch (Exception ex)
     {
         AutoTest.Core.DebugLog.Debug.WriteException(ex);
     }
     finally
     {
         Environment.CurrentDirectory = currentPath;
     }
     return 0;
 }
        public void Should_run_tests()
        {
            return;
            var options = new RunOptions();
            var runner = new RunnerOptions("NUnit");
            options.AddTestRun(runner);
            //runner.AddAssembly(new AssemblyOptions(@"C:\Users\ack\src\AutoTest.Net\src\AutoTest.TestRunner\Plugins\AutoTest.TestRunners.NUnit.Tests.TestResource\bin\Debug\AutoTest.TestRunners.NUnit.Tests.TestResource.dll"));
            runner.AddAssembly(new AssemblyOptions(@"C:\Users\Natalia\Documents\Repos\ic-AutoTest.NET4CTDD\2015\src\AutoTest.TestRunner\Plugins\AutoTest.TestRunners.NUnit.Tests.TestResource\bin\Debug\AutoTest.TestRunners.NUnit.Tests.TestResource.dll"));
            //runner.AddAssembly(new AssemblyOptions(@"C:\Users\ack\src\ClassLibrary1-v40\ClassLibrary1-v40\bin\AutoTest.Net\ClassLibrary1-v40.dll"));
            runner.AddAssembly(new AssemblyOptions(@"C:\Users\Natalia\Documents\Visual Studio 2015\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll"));
            //runner = new RunnerOptions("XUnit");
            runner = new RunnerOptions("MSTest");
            options.AddTestRun(runner);
            runner.AddAssembly(new AssemblyOptions(@"C:\Users\ack\src\AutoTest.Net\src\AutoTest.TestRunner\Plugins\AutoTest.TestRunners.XUnit.Tests.TestResource\bin\AutoTest.Net\AutoTest.TestRunners.XUnit.Tests.TestResource.dll"));
            var process = new TestRunProcess(new feedback());
            var results = process.ProcessTestRuns(options);

            var sb = new StringBuilder();
            sb.AppendLine("");
            foreach (var result in results)
                sb.AppendLine(result.Runner + ", " + result.TestName + ", " + result.Message);

            throw new Exception(sb.ToString());
        }
예제 #9
0
 private RunOptions getRunOptions()
 {
     var options = new RunOptions();
     foreach (var run in _targetedRun.Runners)
         options.AddTestRun(run);
     return options;
 }
 public TargetedRunAssembler(RunOptions options, IAssemblyPropertyReader locator, bool runAssembliesInParallel)
 {
     _options = options;
     _locator = locator;
     _runAssembliesInParallel = runAssembliesInParallel;
 }
예제 #11
0
        public void Debug(CacheTestMessage test)
        {
            try
            {
                AutoTest.Core.DebugLog.Debug.WriteDebug("Starting debug session");
                var found = false;
                var targetFramework = "";
                found = setBreakpointFromMethod(test, ref targetFramework);
                if (!found)
                    found = setBreakpointFromStacktrace(test, ref targetFramework);

                if (!found)
                    return;

                var process = new AutoTestRunnerDebugProcess();
                var assembly = test.Assembly;

                AutoTest.Core.DebugLog.Debug.WriteDebug("Starting process suspended");
                var command = "";
                var options = new RunOptions();
                var runner = new RunnerOptions(getTestRunner(TestRunnerConverter.ToString(test.Test.Runner), test.Assembly, test.Test.Name));
                var asm = new AssemblyOptions(test.Assembly);
                asm.AddTest(test.Test.Name);
                runner.AddAssembly(asm);
                options.AddTestRun(runner);
                AutoTest.Core.DebugLog.Debug.WriteDebug(string.Format("Starting {0}", command));
                var processID = process.StartPaused(options, test.Test.Runner);
                try
                {
                    AutoTest.Core.DebugLog.Debug.WriteDebug("Locating debugger for Visual Studio " + _application.Version);
                    var dbg2 = (EnvDTE80.Debugger2)_application.Debugger;
                    var trans = (EnvDTE80.Transport)dbg2.Transports.Item("Default");
                    EnvDTE80.Engine[] dbgeng;
                    if (_application.Version == "9.0")
                    {
                        dbgeng = new EnvDTE80.Engine[] { trans.Engines.Item("Managed") };
                    }
                    else
                    {
                        if (process.Framework == new Version(4, 0))
                            dbgeng = new EnvDTE80.Engine[] { trans.Engines.Item("Managed (v4.0)") };
                        else
                            dbgeng = new EnvDTE80.Engine[] { trans.Engines.Item("Managed (v2.0, v1.1, v1.0)") };
                    }
                    
                    EnvDTE80.Process2 proc2 = null;
                    foreach (EnvDTE80.Process2 proc in dbg2.GetProcesses(trans, null))
                    {
                        if (proc.ProcessID == processID)
                        {
                            proc2 = proc;
                            break;
                        }
                    }
                    if (proc2 != null)
                        proc2.Attach2(dbgeng);
                }
                catch (Exception ex)
                {
                    AutoTest.Core.DebugLog.Debug.WriteException(ex);
                    throw;
                }
                finally
                {
                    AutoTest.Core.DebugLog.Debug.WriteDebug("Resuming process");
                    process.Resume();
                }
            }
            catch (Exception ex)
            {
                AutoTest.Core.DebugLog.Debug.WriteException(ex);
            }
        }
예제 #12
0
 public AutoTestRunnerFeedback(IRunResultCache cache, IMessageBus bus, RunOptions options)
 {
     _runCache = cache;
     _bus = bus;
     _options = options;
     setTotalTestCount();
 }
예제 #13
0
 private RunOptions generateOptions(TestRunInfo[] runInfos)
 {
     var options = new RunOptions();
     var plugins = new PluginLocator().Locate();
     foreach (var plugin in plugins)
     {
         var testRun = getTests(plugin, runInfos);
         if (testRun != null)
             options.AddTestRun(testRun);
     }
         
     if (options.TestRuns.Count() == 0)
         return null;
     return options;
 }
예제 #14
0
 public TargetedRunAssembler(RunOptions options, IAssemblyReader locator)
 {
     _options = options;
     _locator = locator;
 }
예제 #15
0
 private IEnumerable<Plugin> getPlugins(RunOptions options)
 {
     var path = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "TestRunners");
     return new PluginLocator(path).GetPluginsFrom(options);
 }
 public IEnumerable<Plugin> GetPluginsFrom(RunOptions options)
 {
     var plugins = new List<Plugin>();
     foreach (var plugin in Locate())
     {
         var instance = plugin.New();
         if (options.TestRuns.Where(x => x.ID.Equals(instance.Identifier)).Count() > 0)
             plugins.Add(plugin);
     }
     return plugins;
 }
예제 #17
0
 private IEnumerable<Plugin> getPlugins(RunOptions options)
 {
     var path = Path.Combine(PluginLocator.GetAutoTestDirectory(), "TestRunners");
     return new PluginLocator(path).GetPluginsFrom(options);
 }
예제 #18
0
 private IEnumerable<TargetedRun> getTargetedRuns(RunOptions options)
 {
     var assembler = new TargetedRunAssembler(options, _locator);
     return assembler.Assemble();
 }
예제 #19
0
 public OptionsXmlWriter(IEnumerable<Plugin> plugins, RunOptions options)
 {
     _plugins = plugins;
     _options = options;
 }