2011-09-20 47 views
0

有没有人有任何创建自定义测试类和使用接口的路径?我有一个情况,我需要动态生成测试方法,这似乎是我需要的。我的目标是根据我测试的一些文件生成测试方法。使用IProvideDynamicTestMethods进行Silverlight 4单元测试

Jeff Wilcox在SL3中提到了这个新功能(http://www.jeff.wilcox.name/2008/09/rc0-new-test-features/,请参阅动态测试方法部分),但我找不到任何这方面的例子。

我不知道如何注册我的自定义测试类(它继承自ITestClass)。我看着SL4单元测试源代码才能看到测试类是如何被发现,我发现在UnitTestFrameworkAssembly.cssource 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; 
    } 

看起来它总是使用下面的内置识别TestClass。 我错过了什么吗?我不知道如何让测试框架使用我的自定义TestClass

任何指针赞赏。 谢谢

回答

0

它看起来像现在设置它的唯一方法是为测试运行器编写您自己的UnitTestProvider。好的是代码是可用的,所以这样做并不难。

您可以从codeplex here的默认Vstt中获取代码,并根据需要进行任何更改。我现在仍在试验这个,所以让我们看看这是怎么回事。我通过查看this github项目得到了这个想法。 关键是插入你自己的提供者,这是在Raven.Tests.Silverlight.UnitTestProvider.Example/App.xaml.cs中完成的。

希望这可以帮助别人