Fill with Mock Local
See original GitHub issueI am exploring Moq and kicking the tires on the extension here. Actually, I’ve had it installed forever and am now finally checking it out. 😁
Everything looks handy. Thank you for taking the time to develop it.
The one thing I noticed is that the Fill with Mocks
command seems to create outer instances that are placed in the containing class.
In my case, I would prefer these to be local to the test function.
So instead of this:
public sealed class Tests
{
Mock<IPromote> _previous;
Mock<IPromoted> _promoted;
[Fact]
public async Task Verify()
{
_previous = new Mock<IPromote>();
_promoted = new Mock<IPromoted>();
var sut = new StateAwarePromote(_previous.Object, _promoted.Object);
}
}
It creates this:
public sealed class Tests
{
[Fact]
public async Task Verify()
{
var previous = new Mock<IPromote>();
var promoted = new Mock<IPromoted>();
var sut = new StateAwarePromote(previous.Object, promoted.Object);
}
}
Would it be possible to create a command that does this?
Thank you for any consideration and for making this cool extension!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Using Mockito to mock a local variable of a method
What I need is to set the dateTime to some specific date while it is being tested. Is there a way I can...
Read more >Mockito mock examples
Mockito mocking framework provides different ways to mock a class. Let's look at different methods through which we can mock a class and ......
Read more >Stubbing and Mocking with Mockito and JUnit
Learn how to create true unit tests by mocking all external dependencies in your JUnit classes with the help of Mockito.
Read more >Mocking local variables within the method-under-test
In order to circumvent using a physical database, I mock "helper.LoadFromDB" in my unit test. The delegate I use in the "DoInstead" method ......
Read more >Mockito's Mock Methods
In this tutorial, we'll illustrate the various uses of the standard static mock methods of the Mockito API.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes indeed, 2 commands would be better. The idea with the existing one is that you use it from the Setup method; that’s why it creates fields.
I am going to create 2 commands, 1 for fields and 1 for local variables 👍
I’m closing this as it will be available in the next release of the plugin. Thanks !