我正在使用编码的UI和SpecFlow。我已经使用了以下模板,并且在过去的6个月中该模板工作正常。
https://github.com/aqdasiftekhar/SpecFlowCodedUI/
最近两天,当我尝试重新生成功能文件时,我面临以下问题。
Feature.CS文件中的异常:
We could not find a data exchange file at the path BoDi.ObjectContainerException: Multiple public constructors with same maximum parameter count are not supported! TechTalk.SpecFlow.Utils.CodeDomHelper (resolution path: TechTalk.SpecFlow.CodedUI.MsTest.SpecFlowCodedUITestGenerator)
Please open an issue at https://github.com/techtalk/SpecFlow/issues/
Complete output:
BoDi.ObjectContainerException: Multiple public constructors with same maximum parameter count are not supported! TechTalk.SpecFlow.Utils.CodeDomHelper (resolution path: TechTalk.SpecFlow.CodedUI.MsTest.SpecFlowCodedUITestGenerator)
at BoDi.ObjectContainer.CreateObject(Type type, IEnumerable1 resolutionPath, RegistrationKey keyToResolve) at BoDi.ObjectContainer.TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, IEnumerable1 resolutionPath)
at BoDi.ObjectContainer.CreateObjectFor(RegistrationKey keyToResolve, IEnumerable1 resolutionPath) at BoDi.ObjectContainer.Resolve(Type typeToResolve, IEnumerable1 resolutionPath, String name)
at BoDi.ObjectContainer.<>c__DisplayClass6.b__5(ParameterInfo p)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at BoDi.ObjectContainer.ResolveArguments(IEnumerable1 parameters, RegistrationKey keyToResolve, IEnumerable1 resolutionPath)
at BoDi.ObjectContainer.CreateObject(Type type, IEnumerable1 resolutionPath, RegistrationKey keyToResolve) at BoDi.ObjectContainer.TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, IEnumerable1 resolutionPath)
at BoDi.ObjectContainer.CreateObjectFor(RegistrationKey keyToResolve, IEnumerable1 resolutionPath) at BoDi.ObjectContainer.Resolve(Type typeToResolve, IEnumerable1 resolutionPath, String name)
at BoDi.ObjectContainer.Resolve[T](String name)
at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.CreateContainer(SpecFlowConfigurationHolder configurationHolder, ProjectSettings projectSettings)
at TechTalk.SpecFlow.Generator.TestGeneratorFactory.CreateGenerator(ProjectSettings projectSettings)
at TechTalk.SpecFlow.VisualStudio.CodeBehindGenerator.Actions.GenerateTestFileAction.GenerateTestFile(GenerateTestFileParameters opts)
Command: C:\Users\aqdas\AppData\Local\Microsoft\VisualStudio\15.0_4d3f9930\Extensions\5yaz3tdw.3ra\TechTalk.SpecFlow.VisualStudio.CodeBehindGenerator.exe
Parameters: GenerateTestFile --featurefile C:\Users\aqdas\AppData\Local\Temp\2\tmpF07B.tmp --outputdirectory C:\Users\aqdas\AppData\Local\Temp\2 --projectsettingsfile C:\Users\aqdas\AppData\Local\Temp\2\tmpF07A.tmp
Working Directory: C:\Users\aqdas\ProjectName\ProjectFolder\Project.TestFolder\packages\SpecFlow.2.1.0\tools
我的配置文件是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section
name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<unitTestProvider name="MsTest"
generatorProvider="TechTalk.SpecFlow.CodedUI.MsTest.SpecFlowCodedUITestGenerator, TechTalk.SpecFlow.CodedUI.MsTest"
runtimeProvider="TechTalk.SpecFlow.UnitTestProvider.MsTestRuntimeProvider, TechTalk.SpecFlow" />
</specFlow>
</configuration>
Specflow生成器代码:
namespace TechTalk.SpecFlow.CodedUI.MsTest
{
using System.CodeDom;
using TechTalk.SpecFlow.Generator.UnitTestProvider;
using TechTalk.SpecFlow.Utils;
public class SpecFlowCodedUITestGenerator : MsTestGeneratorProvider
{
public SpecFlowCodedUITestGenerator(CodeDomHelper codeDomHelper)
: base(codeDomHelper)
{
}
public override void SetTestClass(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, string featureTitle, string featureDescription)
{
base.SetTestClass(generationContext, featureTitle, featureDescription);
foreach (CodeAttributeDeclaration customAttribute in generationContext.TestClass.CustomAttributes)
{
if (customAttribute.Name == "Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute")
{
generationContext.TestClass.CustomAttributes.Remove(customAttribute);
break;
}
}
generationContext.TestClass.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference("Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute")));
}
}
}
我已经在GitHub链接https://github.com/techtalk/SpecFlow/issues/1262上发布了问题
我正在使用
如果有人可以帮助我解决此问题,我将非常感谢您。
致谢。
答案 0 :(得分:0)
我刚刚将Specflow版本从2.1更新到1.9,并且可以正常工作。这意味着自定义生成器提供时,specflow 1.9+不支持编码的ui。