0
NAudioEngine是一個單獨的類如何寫在下面的代碼片段執行:如何編寫NUnit測試案例單身類
private bool CanAddNew(object parameter)
{
if (NAudioEngine.Instance.SelectionEnd.Milliseconds != 0)
{
return true;
}
return false;
}
[Test]
public void AddNewCommandMainVMTestTrue()
{
MainVm mainVM = new MainVm();
RelayCommand command = (RelayCommand)mainVM.AddNewCommand;
bool canAddNew = command.CanExecute(null);
Assert.IsTrue(canAddNew);
}
傳遞單值作爲參數。使用該方法訪問靜態/單例值會使得難以單獨進行測試,因爲它與測試中可能無法更改的某些東西耦合在一起。 – Nkosi