[英]How to make a Unit Test out of a Constructor
我正在嘗試使用公共構造函數進行單元測試。
使用Visual Studio 2012
如何使用此構造方法創建一個簡單的單元測試。
public ScenarioSelectViewModel(IEventRecorderSvc service)
{
eventRecordingSvc = svc;
OkCmd = new DelegateCommand<Window>(
OkCmd Executed,
OkCmd CanExecute);
RefreshAvailableScenarioStepExecutionsCommand = new DelegateCommand<object>(
RefreshAvailableScenarioStepExecutionsCommandExecuted,
RefreshAvailableScenarioStepExecutionsCommandCanExecute);
if (RefreshAvailableScenarioStepExecutionsCommand.CanExecute(null))
{
RefreshAvailableScenarioStepExecutionsCommand.Execute(null);
}
}
假設OkCmd
和RefreshAvailableScenarioStepExecutionsCommand
是類ScenarioSelectViewModel中公開公開的屬性。
您正在構造函數中做兩件事,應該對其進行測試:
您可以開始聲明所創建的對象,然后聲明其公開暴露的屬性,即OkCmd.Execute和OkCmd.CanExecute到您期望的對象。 RefreshAvailableScenarioStepExecutionsCommand
。
然后,您可以斷言RefreshAvailableScenarioStepExecutionsCommand命令的執行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.