[英]Run SpecFlow scenario from code
I am trying to run a SpecFlow scenario from code instead of through Test Explorer or the command line.我正在尝试从代码而不是通过测试资源管理器或命令行运行 SpecFlow 场景。 Has someone managed to do this?
有没有人设法做到这一点?
From a scenario, I can extract the method name and test method with recursion, but I cannot run this scenario method.从场景中,我可以通过递归提取方法名称和测试方法,但我无法运行此场景方法。 It seems to need a proper initialize and teardown, but I could't manage to do this.
它似乎需要适当的初始化和拆卸,但我无法做到这一点。
My first thought was to use the TechTalk.SpecFlow.TestRunner
class, but it doesn't seem to have a scenario selection method.我的第一个想法是使用
TechTalk.SpecFlow.TestRunner
类,但它似乎没有场景选择方法。
EDIT on why I want to do this:编辑我为什么要这样做:
We want to run specific scenarios from TFS.我们想从 TFS 运行特定的场景。 It is very cumbersome to connect TestMethods to WorkItems in TFS, because:
在 TFS 中将 TestMethods 连接到 WorkItems 非常麻烦,因为:
I want to create a mechanism where each automated workitem gets the same method assigned.我想创建一种机制,让每个自动化工作项都分配相同的方法。 This method extracts the workitem id and search and executes the scenario(s) with this workitem tagged.
此方法提取工作项 id 并搜索并执行带有此工作项标记的场景。
I had a similar problem since my tests have some dependencies between Scenarios (shame on me, but it saves tons of copy-paste lines per Feature file).我有一个类似的问题,因为我的测试在场景之间有一些依赖关系(我很惭愧,但它为每个功能文件节省了大量的复制粘贴行)。 In most cases I would stick to isolated Scenarios of course.
在大多数情况下,我当然会坚持孤立的场景。
I used reflection我使用了反射
You have to set the (private) field "testRunner" according to your needs of course.当然,您必须根据您的需要设置(私有)字段“testRunner”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.