代码之家  ›  专栏  ›  技术社区  ›  Friendbot

Specflow CodedUI生成器插件不生成功能文件

  •  0
  • Friendbot  · 技术社区  · 7 年前

    可以这就是我现在的处境。我正在使用Specflow 2.2.0将自动单元测试与我们的CodedUI测试工作结合起来。我正在开发一个插件,将CodedUI测试属性添加到Specflow特性测试中,我遇到了一些问题。Specflow没有识别我的插件来为Specflow功能文件生成CodedUI测试属性,我不明白为什么,因为我遵循了文档中的每一条说明,并查看了GitHub上的其他插件,以确保我做得正确。

    以下是我的插件中初始化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

    这是我的应用程序。从我的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.

    1 回复  |  直到 7 年前
        1
  •  0
  •   Andreas Willich    7 年前

    问题是可以找到插件的路径配置错误。
    请参阅SpecFlow论坛中的线程: https://groups.google.com/forum/#!topic/specflow/ZcbuoJLfJ_E