TestLauncher really needs to be refactored at some point.  It's doing too
many things and it inadequately abstracts the complexity of what's
underneath.  Lots of Law of Demeter violations here.

Here's how you would use it:

var fixtureType = typeof(ExampleFixtute);

var testLauncher = new TestLauncher();

testLauncher.RuntimeSetup = new RuntimeSetup();

testLauncher.TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local;

testLauncher.TestPackageConfig.Add(fixtureType.Assembly.Location);

testLauncher.TestExecutionOptions.FilterSet =
FilterUtils.ParseFilterSet("ExactType:" + fixtureType.FullName);

TestLauncherResult result = testLauncher.Run();



Or there's always the following lower level option...

This assumes you are using the current Gallio v3.0.7 trunk builds.

var logger = NullLogger.Instance; // or something else...

if (! RuntimeAccessor.IsInitialized) // avoid issues with reentrance
{
    var runtimeSetup = new RuntimeSetup();
    RuntimeBootstrap.Initialize(runtimeSetup, logger);
}

var testRunnerManager =
RuntimeAccessor.ServiceLocator.Resolve<ITestRunnerManager>();
var testRunner =
testRunnerManager.CreateRunner(StandardTestRunnerFactoryNames.Local);

var progressMonitorProvider = new LogProgressMonitorProvider(logger);
progressMonitorProvider.Run(progressMonitor =>
{
    progressMonitor.BeginTask("Running tests.", 10);

    var testRunnerOptions = new TestRunnerOptions();
    testRunner.Initialize(testRunnerOptions, logger,
progressMonitor.CreateSubProgressMonitor(1));

    var testPackageConfig = new TestPackageConfig();
 
testPackageConfig.AssemblyFiles.Add(typeof(ExampleFixture).Assembly.Location
);

    var testExplorationOptions = new TestExplorationOptions();
    var testExecutionOptions = new TestExecutionOptions();

    Report report = testRunner.Run(testPackageConfig,
testExplorationOptions, testExecutionOptions,
progressMonitor.CreateSubProgressMonitor(8));
    // the report contains all the results...

    testRunner.Dispose(progressMonitor.CreateSubProgressMonitor(1));
});

Jeff. 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Douglas
Sent: Saturday, May 02, 2009 3:57 PM
To: MbUnit.User
Subject: MbUnit Re: Run test fixtures from inside application


On May 2, 10:35 pm, "Jeff Brown" <[email protected]> wrote:
> Take a look at the TestLauncher 
> API.http://www.gallio.org/api/html/T_Gallio_Runner_TestLauncher.html
>

Hi Jeff,

How do I tell the TestLauncher which tests to launch?


It looks like I need to set the TestPackageConfig.AssemblyFiles, like
so:

var launcher = new TestLauncher();

launcher.TestPackageConfig.AssemblyFiles.Add(typeof
(ExampleFixture).Assembly.Location);

Possibly also set the FilterSet, like this?

launcher.TestExecutionOptions.FilterSet = new FilterSet<ITest>(new
TypeFilter<ITest>(new EqualityFilter<string>(typeof
(ExampleFixture).AssemblyQualifiedName), true));

Running that with launcher.Run(), I get a "The runtime has not been
initialized." exception. Guessing from the documentation, perhaps something
like this:

launcher.RuntimeSetup = new Gallio.Runtime.RuntimeSetup();
launcher.RuntimeSetup.SetConfigurationFilePathFromAssembly(typeof
(ExampleFixture).Assembly);

Then I get a "The runtime could not be initialized." exception, which I
suppose is an improvement. Having a look at the SampleRunner source [1], I
can't see where it sets up a RuntimeSetup, but it looks like I need to set
the TestRunnerFactoryName too, I tried adding this,

launcher.TestRunnerFactoryName = StandardTestRunnerFactoryNames.Local;

but I feel like I'm shooting in the dark. How do I get it to find my
fixture?

Douglas

[1]
http://www.google.com/codesearch/p?hl=en#--kv20-JHyI/v3/src/Gallio/Gallio/Fr
amework/Utilities/SampleRunner.cs&q=TestLauncher%20Gallio&l=259


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to