我們有一些由步驟組成的測試工作流程。 現在我想構建類來表示它。數據流的設計模式
例如
Step 1: Get edit control for username
Step 2: Write username into the control
Step 3: Get edit control for password
Step 4: Write password into the control
Step 5: Click Login Button
的問題是:我怎麼能有這些步驟,方便地交換信息? 如何輕鬆使用步驟2的代碼中的步驟1的編輯控件?
此刻,我只是有下面的代碼:
public abstract class TestCase
{
// the Steps to build the test
public IList<TestStep> TestSteps { get; set; }
public TestCase()
{
this.TestSteps = new List<TestStep>();
}
public abstract void Run();
public override string ToString()
{
return this.GetType().Name;
}
}
public class TestStep
{
public int StepNumber { get; set; }
public Func<bool> StepFunc { get; set; }
}
現在我想在第一步的控制,用它在第二步等等。
想到具有不同StepFunc的返回值適合需要 或特定TestStep派生類中的成員。但是可能有更好的方法。
請注意:目前我無法一步完成此操作。
任何想法高度讚賞!
步驟X需要步驟Y *和步驟Z的結果嗎?例如,步驟X需要控制用戶名和密碼。 –
當然,這可能是必要的。只是舉了一個簡單的例子,讓它更容易談論它。 –
誰應該知道參數的來源?步驟X是否應該知道它需要步驟1和步驟3(而不是2和4)的結果,還是控制器應該知道?我認爲你需要以某種方式「硬」 - 對它進行編碼,你不能爲所有參數自動推導出正確的步驟。 –