question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create Mock calls constructor

See original GitHub issue

Im 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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
florinncommented, Jun 24, 2017

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:

const mock = TypeMoq.Mock.ofType<FooService>();
2reactions
stijnherremancommented, Aug 25, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found