Create Mock calls constructor
See original GitHub issueIm trying to setup mock object like thus
let account: TypeMoq.Mock<IAccount> = TypeMoq.Mock.ofType<IAccount>(Account);
Account class has a constructor, and this constructor is called during Mock object creation. Im not sure if this is made intentionally or not, but obviously when we write test we want to avoid any logic in mocked classes
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Mock a constructor with parameter - java - Stack Overflow
The logic in the constructor A(String test) and check() are the things I am trying to mock. I want any calls like: new...
Read more >Mock constructor calls with Mockito - David Vlijmincx
With the mockConstruction you can mock calls made to the constructor. For example, we mock the constructor for the class Dog . The...
Read more >Mock Java Constructors With Mockito | Configuration ... - rieckpil
The new method that makes mocking object constructions possible is Mockito.mockConstruction() . This method takes a non-abstract Java class that ...
Read more >Mockito 3.5.0 API - javadoc.io
New API makes it possible to use constructor when creating an instance of the mock. This is particularly useful for mocking abstract classes...
Read more >Mock Constructor - DZone
Created instances are used as parameter/s passed to some dependency object. This dependency object of testing class is most probably mocked. In ...
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
Starting with version 1.0.0, typemoq supports dynamic mocking that does exactly what you want.
Simply create the mock like this and the constructor of your class is not going to get called:
What if one of the constructor arguments also has a constructor that requires arguments?
It’s unfortunate if there are technical limitations preventing a proper solution. In its current state however, I find TypeMoq to be unusable for me.