[Jetbrains Plugin] NSubstituteComplete

  • 266
  • 0
  • 2022-08-14

最近被同事推薦了這個好用的套件
我也想跟大家分享
讓你在寫測試時,速度加倍
那就是 NSubstituteComplete

我使用的IDE是 Rider
搭配 NUnit 和 NSubstitute 這兩個 package

首先,我先建立一個 class
裡面有一個 constructor 與一個 method
然後我為這個 class 寫一個單元測試

public class ExampleService
{
	public ExampleService(IDependencyService1 service1, IDependencyService2 service2)
	{
	}

	public void DoSomething(int parameter1, string parameter2)
	{
	
	}
}

接著,我在測試中建立 ExampleService
在 constructor 的部分,使用快捷鍵 Alt + Enter 呼叫出 Action List
選擇 Fill missing arguments with NSubstitute mocks

就會自動產生相對應的 field 和 substitute 替身

接著在我的測試中呼叫 method
在參數的部分打上 Arg 後,intellisense 跳出這些選項給我選擇

這邊我選擇了第三個,自動幫我補齊兩個參數

因為這個套件的幫助,少打了非常多字
在撰寫測試上能節省很多時間
大家也試著使用看看吧!


官網介紹:NSubstituteComplete