开发者

Multiple Silverlight Unit Test Projects in Solution

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 ex开发者_StackOverflow中文版ecute 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜