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 SledEventListener { 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); }
public void BeginRunTest(string filename, string[] testNames) { State = TestRunnerState.Running; var nameFilter = new SimpleNameFilter(); foreach (var testName in testNames) { nameFilter.Add(testName); } CoreExtensions.Host.InitializeService(); var testPackage = new TestPackage(filename); _testRunner.Load(testPackage); _testRunner.BeginRun(this, nameFilter); var stateCheckerThread = new Thread(() => { while (_testRunner.Running) { Thread.Sleep(100); } State = TestRunnerState.Idle; }); stateCheckerThread.IsBackground = true; stateCheckerThread.Name = "stateCheckerThread"; stateCheckerThread.Start(); }
public TestRun(string fileName) { TestPackage testPackage = new TestPackage(fileName); remoteTesRunner = new RemoteTestRunner(); remoteTesRunner.Load(testPackage); }
private void InitAndLoadTestPackage() { if (_testAssemblyLocation == null) { throw new Exception("No test assembly to load"); } TestPackage testPackage = new TestPackage(_testAssemblyLocation); _remoteTestRunner.Load(testPackage); TestExecutionContext.CurrentContext.TestPackage.Settings.Add("StopOnError", true); }
static void Main(string[] args) { CoreExtensions.Host.InitializeService(); TestSuiteBuilder builder = new TestSuiteBuilder(); TestPackage testPackage = new TestPackage(@"d:\Programming\RoboFootball\Platform\Arbiter.Test\bin\Debug\Arbiter.Test.dll"); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load(testPackage); remoteTestRunner.Run(new NullListener(), new SingleTestFilter("StartWithOneTeam"), false, LoggingThreshold.Error); }
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); }
private TestResult runTest() { CoreExtensions.Host.InitializeService(); TestPackage testPackage = new TestPackage(this.path); RemoteTestRunner rtr = new RemoteTestRunner(); rtr.Load(testPackage); TestResult tr = rtr.Run(new NullListener(), TestFilter.Empty, false, LoggingThreshold.Error); XmlResultWriter xmlw = new XmlResultWriter(Directory.GetCurrentDirectory() + @"\TempResults\testResult.xml"); xmlw.SaveTestResult(tr); return(tr); }
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); }
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); }
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)); }
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); }
public TestRunner GetTestRunner() { //Doesn't help... //if (!CoreExtensions.Host.Initialized) // CoreExtensions.Host.InitializeService(); var pack = new TestPackage(_assemblyLocation); pack.ConfigurationFile = _assemblyLocation + ".config"; var nu = new RemoteTestRunner(); //var nu = new SimpleTestRunner(Thread.CurrentThread.ManagedThreadId); //var nu = new ThreadedTestRunner(new RemoteTestRunner()); if (!nu.Load(pack)) { throw new ApplicationException("what... very rude stuff happened"); } return(nu); }
public override void ExecuteTest(object instance, string testId, string methodName) { using (RemoteTestRunner testRunner = new RemoteTestRunner()) { TestPackage package = new TestPackage("FieldTest"); package.Assemblies.Add(instance.GetType().Assembly.Location); testRunner.Load(package); var testCount = testRunner.CountTestCases(new NameFilter()); var testToRun = GetMatchingTest(methodName, testRunner.Test); var testFilter = new NameFilter(testToRun.TestName); TestResult result = testRunner.Run(new NullListener(), testFilter); if (result.IsSuccess) { _testResultReporter.ReportTestResult(testId, "Passed", string.Empty); } else { result = GetMatchingTestResult(methodName, result); if (result != null) { if (result.ResultState == ResultState.Inconclusive) { _testResultReporter.ReportTestResult(testId, "Inconclusive", string.Format("{0} {1}", result.Message, result.StackTrace)); } else { _testResultReporter.ReportTestResult(testId, "Failed", string.Format("{0} {1}", result.Message, result.StackTrace)); } } else { _testResultReporter.ReportTestResult(testId, "Failed", string.Empty); } } testRunner.Unload(); } }
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); }
public static void Run(string loc, string[] args) { MainArgs ma = MainArgs.ValueOf(args); string excludes = ma.Get("exclude", null); string includes = ma.Get("include", null); string outfile = ma.Get("out", "TestResult.xml"); CoreExtensions.Host.InitializeService(); TestSuiteBuilder builder = new TestSuiteBuilder(); TestPackage testPackage = new TestPackage(loc); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load(testPackage); TestSuite suite = builder.Build(testPackage); TestSuite root = suite.Tests[0] as TestSuite; List <TestFixture> fixtures = new List <TestFixture>(); ScanFixtures(root, fixtures); Console.WriteLine("--------------- {0} TextFixtures --------------- \n", fixtures.Count); //TestName testName = ((TestMethod) ((TestFixture) test.Tests[0]).Tests[0]).MethodName; ITestFilter filter = null; bool hasInclude = !string.IsNullOrEmpty(includes); bool hasExclude = !string.IsNullOrEmpty(excludes); if (hasInclude) { if (hasExclude) { // incldue+exclude; exclude first filter = new AndFilter(new ITestFilter[] { new NotFilter(new CategoryFilter(excludes.Split(','))), new SimpleNameFilter(includes.Split(',')), }); } else { // include filter = new SimpleNameFilter(includes.Split(',')); } } else // no include { if (hasExclude) { // Only exclude filter = new NotFilter(new CategoryFilter(excludes.Split(','))); } else { // none filter = new TrueFilter(); } } int succCnt = 0, failCnt = 0, errorCnt = 0, assertCnt = 0; TestResult tr = new TestResult(new TestName()); RunEventListener eventLsn = new RunEventListener(); foreach (TestFixture tf in fixtures) { TestResult result = tf.Run(eventLsn, filter); FixtureResult fr = null; if (result.Results != null) { fr = new FixtureResult(result); succCnt += fr.succCnt; failCnt += fr.failCnt; errorCnt += fr.errorCnt; assertCnt += fr.assertCnt; Console.WriteLine(" Done: " + fr.ToString()); } else { Console.WriteLine(" Done: no result."); } tr.AddResult(result); } if (failCnt + errorCnt == 0) { Console.WriteLine( @"========================================= Test Success! Cases: {0}, asserts: {1} =========================================", succCnt, assertCnt); } else { Console.WriteLine( @"================================================================================= Test with errors: Cases: {0}, asserts: {4}, Succ: {1}, fail:{2}, error: {3} =================================================================================", succCnt + errorCnt + failCnt, succCnt, failCnt, errorCnt, assertCnt); } XmlResultWriter w = new XmlResultWriter(outfile); w.SaveTestResult(tr); Console.WriteLine("Result save to: {0}", outfile); }
public void LoadAssembly() { Test test = runner.Load(testsDll); Assert.IsNotNull(test, "Unable to load assembly"); }
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 "); }