![](/img/trans.png)
[英]SpecFlow Visual Studio extension attempted to use SpecFlow code-behind generator 1.9
[英]Extension for Specflow in visual studio
我在Visual Studio上使用specflow進行了一組測試,其中一些測試步驟如下:
Given the data in file /foo/bar/data.txt
我想實現一個Visual Studio擴展,以便可以單擊/foo/bar/data.txt並打開文件。
我有一個模糊的想法,想使用類似Visual Studio文字的裝飾,但是我真的不知道是否有更簡單的方法。 此外,我正在尋找一種適用於Visual Studio 2013及更高版本的解決方案,據我所知,舊版本不支持裝飾物。 有任何想法嗎?
一種可能的解決方案是使用Visual Studio外接程序創建一個新的菜單項,以這種方式,當您單擊一行並選擇此菜單選項時,您可以執行一個操作(讀取並解析該行並打開文件)。 可以按照以下步驟進行:
文件->新項目->其他類型->可擴展性-> Visual Studio加載項,並實現IDTCommandTarget
Commands2 commands = (Commands2)_applicationObject.Commands;
object[] contextGUIDS = new object[] { };
CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
CommandBar vsBarProject = cmdBars["Code Window"];
scenarioCommand = commands.AddNamedCommand2(_addInInstance, "OpenScenario", "Open scenario", "Open scenario data", true);
scenarioCommand.AddControl(vsBarProject);
然后,在Exec方法中,只需讀取該行,獲取文件路徑,然后:
Process.Start(resource)
當然,如果在QueryStatus方法中是specFlow文件,則僅顯示菜單選項:
dynamic docName = _applicationObject.ActiveDocument.FullName;
if (CmdName == OpenScenarioCmd && !((string)docName).EndsWith(".feature"))
{
StatusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusInvisible;
}
else if (CmdName == OpenScenarioCmd)
{
StatusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
}
這不是完美的,因為您必須顯示一個菜單,但是它可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.