开发者

using IProvideDynamicTestMethods for silverlight 4 unit tests

开发者 https://www.devze.com 2023-04-06 09:35 出处:网络
Has anyone had any lucking creating their custom test class and using the IProvideDynamicTestMethods interface? I have a case where I need to dynamically generate test methods and this seems to be wha

Has anyone had any lucking creating their custom test class and using the IProvideDynamicTestMethods interface? I have a case where I need to dynamically generate test methods and this seems to be what I need. I goal is to have test methods generated based on some files I am testing.

Jeff Wilcox mentions this as a new feature in SL3 ( http://www.jeff.wilcox.name/2008/09/rc0-new-test-features/ , see the dynamic test methods section), but I was unable to find any examples of this.

I don't know how to register my custom test class (it inherits from ITestClass). I looked at the SL4 unit testing source to see how the test class are discovered and I found the following in UnitTestFrameworkAssembly.cs source link

    /// <summary>
    /// Reflect and retrieve the test class metadata wrappers for 
    /// the test assembly.
    /// </summary>
    /// <returns>Returns a collection of test class metadata 
    /// interface objects.</returns>
    public ICollection<ITestClass> GetTestClasses()
    {
        ICollection<Type> classes = ReflectionUtility.GetTypesWithAttribute(_assembly,开发者_开发问答 ProviderAttributes.TestClass);
        List<ITestClass> tests = new List<ITestClass>(classes.Count);
        foreach (Type type in classes)
        {
            tests.Add(new TestClass(this, type));
        }
        return tests;
    }

It looks like it will always use the built-in TestClass. Am I missing something? I don't how to get the test framework to use my custom TestClass

Any pointers appreciated. Thanks


It looks like the only way to set this up right now is to write your own UnitTestProvider for the test runner. The good thing is the code is available, so it's not too hard to do this.

You can either grab the code from the default Vstt from codeplex here and make any changes you you like to it. I'm still experimenting with this right now, so lets see how this goes. I got this idea by looking at this github project. The key was to plug in your own provider, which was done in Raven.Tests.Silverlight.UnitTestProvider.Example/App.xaml.cs.

Hope this helps someone

0

精彩评论

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

关注公众号