2016-08-02 122 views
0

所以我有幾個測試,我已經重複使用步驟內的步驟。導航到Specflow步驟從步驟定義

但是我現在在維護方面有一個噩夢,因爲我無法輕鬆地在步驟之間導航。

下面是一個例子:

[Given(@"I have an order")] 
    public void GivenIHaveAnOrder() 
    { 
     Given("an open store"); 
     Given("I am an existing customer"); 
     Given("I am on homepage"); 
     When("I search for a component"); 
     When("I add the component to my basket"); 
    } 

如何瀏覽到這些內部步驟之一?

如果我想導航到「當(」我搜索組件「);」一步我不能。

如果我在功能文件,我可以簡單地右鍵單擊該步驟和「去定義」,但我不能這樣做。有沒有人有辦法解決嗎?

+0

我找到的唯一解決方案是使用visual studio find搜索步驟文本。 –

回答

1

我假設你正在調用Given/When-函數的步驟,因爲它們在不同的綁定類中。我對嗎?

有比使用這個功能更好的方法。

您是否看過驅動程序概念和上下文注入? 看一看這裏:http://www.specflow.org/documentation/Context-Injection/

您對您的步驟邏輯簡單地解壓縮到一個驅動程序類,並在不同的步班從它那裏得到一個實例:

class Driver 
{ 
    public void AnOpenStore() 
    { 
     ... 
    } 
} 

[Binding] 
public class StepClass1 
{ 
    private Driver _driver; 

    public StepClass1(Driver driver) 
    { 
      _driver = driver; 
    } 

    [Given(@"I have an order")] 
    public void IHaveAnOrder() 
    { 
      _driver.AnOpenStore(); 
    } 
} 

[Binding] 
public class StepClass2 
{ 
    private Driver _driver; 

    public StepClass2(Driver driver) 
    { 
      _driver = driver; 
    } 

    [Given(@"an open store")] 
    public void AnOpenStore() 
    { 
      _driver.AnOpenStore(); 
    } 
} 

當你安排你一步實現這樣,其他步驟的重用更容易。

+0

我完全同意,即時在重寫測試過程中,我希望我可以有一個快捷方式導航到步驟,但它現在似乎不正確。 – Festivejelly