I recommend using Unitverse C# Unit Test Generator Visual Studio extension as it supports Mock and NSubstitute and generates full test classes.
A Diagnostic Analyzer and CodeFix Provider aimed to automate mocks creating and configuring.
You can use it as a Visual Studio Extension or install as a NuGet package.
For Visual Studio Code you should install a NuGet package and enable Roslyn Analyzers, see Example project.
Additionally, you can configure variable and field name templates.
Quick introduction:
Create the instance of your Service Under the Test (SUT) in the Constructor or TestInitialize (SetUp for NUnit) marked method.
After that you can see code analysis error and the following suggestions (lightbulbs):
- to create a constructor without parameters
- to fill with mocks
Choose "Fill with mocks" - it will create the mocks required for your service and put them into constructor.
Create TestMethod (Test for NUnit, Fact or Theory for xUnit) marked method and write here a call of any methods of your SUT.
If SUT's method uses any of injected instances Visual Studio shows you code analysis info.
Choose "Setup mocks with callbacks" or "Setup mocks" - it will setup the mock's methods and calls VerifyAll for each of them.
After that change all default(type) expressions to values you want.
This tool has been working well for my own personal needs, but outside that its future depends on your feedback. Feel free to open an issue.
Any donations during this time will be directed to local charities at my own discretion.
Privacy Notice: No personal data is collected at all.