c# - 代码后面的规范流有语法错误或重复代码
问题描述
我有一个由几个项目组成的解决方案。我的解决方案中有 3 类项目。第一类仅包括 .feature 文件。第二类只包括绑定。第三个包括驱动程序,其中包括绑定中使用的一组函数,以与我正在测试的软件接口进行通信。
当我构建我的解决方案时,文件背后的一些代码 (.feature.cs) 已损坏。以下是我构建解决方案后得到的屏幕截图:
Visual Studio 中的构建错误
以下是损坏的 .feature.cs 文件的示例:
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:2.3.0.0
// SpecFlow Generator Version:2.3.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace AcceptanceTests.Controllers.Images
{
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.3.0.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
public partial class GetImagesFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
pr// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:2.3.0.0
// SpecFlow Generator Version:2.3.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
+ Designer generated code
注意这里有重复的代码块。似乎重新生成的代码被添加到旧代码中间的某个地方(我们看到“pr// ---”)。
另一个例子是包含语法错误的代码文件,例如缺少括号或格式不正确。
我的解决方案中的所有测试项目都有以下包:
- MSTest.TestAdapter v1.3.2
- MSTest.TestFramework v1.3.2
- SpecFlow v2.3.1
- SpecFlow.MsTest v2.3.1
- .Net 框架 4.6.2
单元测试提供程序是 mstest.v2。
到目前为止,我已尝试清理 %TEMP% 中的 SpecFlow 文件。我确保所有项目都安装了相同版本的 SpecFlow。我已经清理了解决方案并完成了重建。如果我在每个功能文件上单独运行自定义工具,我永远不会遇到这个问题。
我感谢您的帮助!
解决方案
该问题是由具有长名称、嵌套文件夹和长测试场景描述的项目引起的。我缩短了其中一个功能文件中的场景描述,该文件经常损坏其背后的代码,之后问题就消失了。
推荐阅读
- dart - 使用 bloc 框架时如何为文本字段提供默认值
- sql - 获取过去 30 天内的行,不包括今天
- regex - 正则表达式来识别无括号的 if 语句
- python - 当我将它写入excel时,pandas pivot_table() 在我的数据框中放置了一个不需要的列,为什么?
- python - Pandas 子图布局在这种情况下不起作用
- r - 如何将我的列(字符)转换为 POSIXct 以创建时间序列?
- http-headers - iframe 重定向时如何传递授权标头?
- java - 会话值在 Safari 浏览器中不可用
- json - How to read an object from an script of index.html in angular
- php - Php - 如何扫描大图像文件夹并删除未使用的图像