2017-08-30 48 views
0

好的。所以这就是我所处的位置。我使用Specflow 2.2.0将自动化单元测试与我们的CodedUI测试工作配对。我正在开发一个插件来将CodedUI Test属性添加到Specflow Feature测试中,我遇到了一些问题。 Specflow无法识别我的插件来为Specflow特性文件生成CodedUI测试属性,我不明白为什么,因为我遵循了文档中的每条指令以及查看GitHub上的其他插件以确保我做得正确。Specflow CodedUI Generator插件不生成功能文件

我在自己的类库项目中拥有该插件,并将其dll autocopies构建到Spectro所在解决方案中的packages文件夹。我编辑了汇编文件以指向生成器。我有事件处理程序的初始化程序。我的CodedUI项目的app.config中的所有内容都是正确的,据我所知,我仍然遇到错误。这里是我的一切都在问候插件和其他相关作品:

这里是我的插件的代码初始化IGenerator类:

namespace SpecflowCUITPluginLib 
{ 
    public class CodedUiPlugin : IGeneratorPlugin 
    { 
        public void Initialize(GeneratorPluginEvents generatorPluginEvents, GeneratorPluginParameters generatorPluginParameters) 
        { 
            generatorPluginEvents.CustomizeDependencies += this.GeneratorPluginEventsOnCustomizeDependencies; 
        } 
        private void GeneratorPluginEventsOnCustomizeDependencies(object sender, CustomizeDependenciesEventArgs customizeDependenciesEventArgs) 
        { 
            string unitTestProviderName = 
              customizeDependenciesEventArgs.SpecFlowProjectConfiguration.SpecFlowConfiguration.UnitTestProvider; 
            if (unitTestProviderName.Equals("mstest", StringComparison.InvariantCultureIgnoreCase) 
              || unitTestProviderName.Equals("mstest.2010", StringComparison.InvariantCultureIgnoreCase)) 
            { 
                customizeDependenciesEventArgs.ObjectContainer.RegisterTypeAs<CodedUIGeneratorProvider, IUnitTestGeneratorProvider>(); 
            } 
        } 
        #region IGeneratorPlugin Members 
        public void RegisterConfigurationDefaults(TechTalk.SpecFlow.Generator.Configuration.SpecFlowProjectConfiguration specFlowConfiguration) { } 
        public void RegisterCustomizations(BoDi.ObjectContainer container, TechTalk.SpecFlow.Generator.Configuration.SpecFlowProjectConfiguration generatorConfiguration) 
        { 
            container.RegisterTypeAs<CodedUIGeneratorProvider, IUnitTestGeneratorProvider>(); 
            container.RegisterTypeAs<MsTest2010RuntimeProvider, IUnitTestRuntimeProvider>(); 
        } 
        public void RegisterDependencies(BoDi.ObjectContainer container) { } 
        #endregion 
    } 
} 

这里是我的发电机提供的代码,位于一个单独的cs文件:

namespace SpecflowCUITPluginLib 
{ 

    public class CodedUIGeneratorProvider : MsTest2010GeneratorProvider 
    { 
        public CodedUIGeneratorProvider(CodeDomHelper codeDomHelper) 
            : base(codeDomHelper) { } 
        private const string TestClassAttribute = @"Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute"; 
        private const string CodedUiTestClassAttribute = @"Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute"; 
        private const string DeploymentItemAttribute = "Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute"; 
        public override void SetTestClass(TestClassGenerationContext generationContext, string featureTitle, string featureDescription) 
        { 
            base.SetTestClass(generationContext, featureTitle, featureDescription); 
            foreach (CodeAttributeDeclaration declaration in generationContext.TestClass.CustomAttributes) 
            { 
                if (declaration.Name == TestClassAttribute) 
                { 
                    generationContext.TestClass.CustomAttributes.Remove(declaration); 
                    break; 
                } 
            } 
            generationContext.TestClass.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(CodedUiTestClassAttribute))); 
            string filename = new Uri(this.GetType().Assembly.CodeBase).LocalPath; 
            // Add deployment item in each test for the driver. 
            generationContext.TestClass.CustomAttributes.Add(
                new CodeAttributeDeclaration(
                    new CodeTypeReference(DeploymentItemAttribute), 
                    new CodeAttributeArgument(new CodePrimitiveExpression("SpecflowCUITPluginLib.SpecFlowPlugin.dll")))); 
        } 
    } 
} 

这里是我添加到装配文件的行:

[assembly: GeneratorPlugin(typeof(CodedUiPlugin))] 

Here is a screencap of my build settings for the plugin project

这里是我的app.config从我CodedUI项目

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
  <configSections> 
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" /> 
  </configSections> 
  <specFlow> 
    <unitTestProvider name="MsTest" /> 
    <plugins> 
      <add name="SpecflowCUITPluginLib.SpecflowPlugin" path=".\MedchartUITesting\packages\specflow2.2.0\tools" type="Generator" /> 
    </plugins> 
  </specFlow> 
</configuration> 

而且不管我做什么,我得到这个错误我的特点文件:#error Generation error: Unable to find plugin in the plugin search path: SpecflowCUITPluginLib.SpecflowPlugin. Please check http://go.specflow.org/doc-plugins for details.

任何人看到的溶液或这是一个问题,因为在这个时候我真的不知道我应该在哪里寻找解决方案。

回答

相关问题