views:

147

answers:

2

I am building out a number of Silverlight 4.0 libraries that are part of the same solution. I like to break them into separate projects and have a Unit Test project for each:

SolutionX
-LibraryProject1
---Class1.cs
---Class2.cs
-LibraryProject1.Test
---Tests1.cs
---Tests2.cs
-LibraryProject2
---Class1.cs
---Class2.cs
---CLass3.cs
-LibraryProject2.Test
---Tests1.cs
---Tests2.cs
---Tests3.cs
-LibraryProject3
---Class1.cs
-LibraryProject3.Test
---Tests1.cs

This works great when using VS regular test projects and infrastructure because I can create and execute list of test that are aggregated from each Test project. But with the Silverlight Unit Test Framework since the Silverlight Unit Test Project must be the "start up project" I cannot figure how to run a collection of tests from each test project in one go. I have to run each separately then switch the starting project each time. I would prefer to avoid create complex build scripts or build definitions - is there a way to run all the tests at once?

-Thanks

A: 

Yeah, unfortunately without the test list support it isn't so easy.

I would recommend combining the tests into one Silverlight unit test project, putting the different sets into folders.

You can then use the Tag Expression feature of the framework to select which test(s) you actually want to run at runtime. The feature is easier to use in the new April 2010 release of the Silverlight Toolkit.

Jeff Wilcox
That's what I suspected - I am using the April release. I was trying to avoid a single test project because I like to keep the test project and the project under test together as a pair - better separation - rather then one uber project that test everything. That makes it hard to reuse or version a specific library project in the future in another solution. It would be nice to see integration into the VS test project infrastructure in a future release to get the test list support.Still, thanks for the work you've done on this so far - it's an a great Silverlight tool for us.
IUnknown
A: 

I don't know if you are still looking for a solution for this but it is possible to create one project that will run all tests in multiple assemblies. I just created one project that doesn't have any tests in it, give it a reference to all your other test assemblies, and then change the Application_Startup method to something like so.

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        UnitTestSettings settings = UnitTestSystem.CreateDefaultSettings();
        var testAssemblies = Deployment.Current.Parts.Where(p => p.Source.Contains("Tests")).ToList();
        foreach(var assembly in testAssemblies)
        {
            settings.TestAssemblies.Add(new AssemblyPart().Load(GetResourceStream(new Uri(assembly.Source, UriKind.Relative)).Stream));
        }

        RootVisual = UnitTestSystem.CreateTestPage(settings);
    }

You will need to change p.Source.Contains("Tests") to some method that can match all your unit test projects but you can then run the one project and it will give you nice tree view of all the different assemblies that were run.

Stephan