Programmically launch TestRunner

267 views
Skip to first unread message

Chris

unread,
Apr 19, 2011, 6:19:22 PM4/19/11
to galli...@googlegroups.com
Hello all,

I'd like to be able to programmatically execute all tests in an assembly as if I were using Gallio.Echo or Gallio.Icarus (basically, I just want finer grained control over what those runners offer).

It looks like I want to create and use an instance of Gallio.Runner.TestLauncher, but I can not get it to execute.  The following code:

ILogger logger = (ILogger)new RichConsoleLogger(NativeConsole.Instance);
var launcher = new TestLauncher()
{
  Logger = logger,
  ProgressMonitorProvider = NullProgressMonitorProvider.Instance
};
launcher.RuntimeSetup = new Gallio.Runtime.RuntimeSetup();
Assembly assembly = typeof(TestRunner).Assembly;
FileInfo assemblyInfo = new FileInfo(assembly.Location);
launcher.AddFilePattern(assembly.Location);
launcher.Run();

--- Produces the following Exception:

Gallio.Runtime.RuntimeException was unhandled
  Message="Could not resolve component for service type 'Gallio.Runner.Projects.ITestProjectManager' because there do not appear to be any components registered and enabled for that service type."
  Source="Gallio"
  StackTrace:
       at Gallio.Runtime.Extensibility.RegistryServiceLocator.ResolveNonDisabledDescriptor(Type serviceType) in c:\Server\Projects\MbUnit v3.2\Work\src\Gallio\Gallio\Runtime\Extensibility\RegistryServiceLocator.cs:line 197
       at Gallio.Runtime.Extensibility.RegistryServiceLocator.ResolveImpl(Type serviceType) in c:\Server\Projects\MbUnit v3.2\Work\src\Gallio\Gallio\Runtime\Extensibility\RegistryServiceLocator.cs:line 161
       at Gallio.Runtime.Extensibility.RegistryServiceLocator.Resolve[TService]() in c:\Server\Projects\MbUnit v3.2\Work\src\Gallio\Gallio\Runtime\Extensibility\RegistryServiceLocator.cs:line 52
       at Gallio.Runner.TestLauncher.RunWithRuntime() in c:\Server\Projects\MbUnit v3.2\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 515
       at Gallio.Runner.TestLauncher.Run() in c:\Server\Projects\MbUnit v3.2\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 480
       at MDWTests.TestRunner.Main(String[] args) in C:\scm\dev\core\MDWorkstation-LED\MdwTests\TestRunner.cs:line 55
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

--- End Exception

I assume this has something to do with the registry not being loaded with plugins.  What else do I have to call to set up a basic runner for one assembly?  Is there any simpler way?

Thanks,

~Chris

Graham Hay

unread,
Apr 20, 2011, 9:34:44 AM4/20/11
to galli...@googlegroups.com
Have you initialised the runtime? (See RuntimeBootstrap.Initialize(runtimeSetup, runtimeLogger)).

--
You received this message because you are subscribed to the Google Groups "gallio-user" group.
To post to this group, send email to galli...@googlegroups.com.
To unsubscribe from this group, send email to gallio-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gallio-user?hl=en.

Chris

unread,
Apr 21, 2011, 9:18:34 AM4/21/11
to galli...@googlegroups.com
Yeah, it looks like adding the following worked:


ILogger logger = (ILogger)new RichConsoleLogger(NativeConsole.Instance);
var setup = new Gallio.Runtime.RuntimeSetup();
setup.AddPluginDirectory(@"..\GallioBundle\bin");
RuntimeBootstrap.Initialize(setup, logger);

I had to add the addPluginDirectory because the .plugin files weren't in the execution directory.

It looks like that even invoking through code, however, that it executes the test cases in some sort of isolated environment (a different process? Gallio.Host?)

Is there any way that I can get the tests to execute in same application context/process?  I want to optimize for speed and the ability to attach the debugger.

Thanks,

~Chris

Chris

unread,
Apr 21, 2011, 9:55:37 AM4/21/11
to galli...@googlegroups.com
The option I was looking for was

launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local;

Works the way I expect now :)  Complete code snippet:


      ILogger logger = (ILogger)new RichConsoleLogger(NativeConsole.Instance);
      var setup = new Gallio.Runtime.RuntimeSetup();
      setup.AddPluginDirectory(pluginDir);
      RuntimeBootstrap.Initialize(setup, logger);

      var launcher = new TestLauncher()
      {
        Logger = logger,
        ProgressMonitorProvider = NullProgressMonitorProvider.Instance
      };
      launcher.RuntimeSetup = setup;
      Assembly assembly = this.GetType().Assembly;

      FileInfo assemblyInfo = new FileInfo(assembly.Location);
      launcher.TestProject.TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local;
      launcher.AddFilePattern(assembly.Location);
      launcher.Run();

~Chris


Reply all
Reply to author
Forward
0 new messages