Questions tagged [automocking]

Use automocking for questions related to programmatic creation of mocks from source code and metadata.

References

70 questions
31
votes
6 answers

AutoFixture.AutoMoq supply a known value for one constructor parameter

I've just started to use AutoFixture.AutoMoq in my unit tests and I'm finding it very helpful for creating objects where I don't care about the specific value. After all, anonymous object creation is what it is all about. What I'm struggling with…
Nick Soper
  • 765
  • 1
  • 5
  • 12
18
votes
1 answer

What are the differences between MOQ and AutoFixture?

I have a fair amount of experience using MOQ, while I've recently have stumbled into AutoFixture. What are the differences between these frameworks?
Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114
12
votes
2 answers

AutoFixture/AutoMoq ignores injected instance/frozen mock

The short takeaway now that the solution has been found: AutoFixture returns frozen the mock just fine; my sut that was also generated by AutoFixture just had a public property with a local default that was important for the test and that…
TeaDrivenDev
  • 6,591
  • 33
  • 50
12
votes
1 answer

AutoFixture as an Automocking container vs Automocking differences?

I started to use moq but from my understanding I always have to mock up all the methods that could be called even if I really do not care about them. Sometimes it takes so long to mockup stuff you forget what you want to do. So I been looking at…
chobo2
  • 83,322
  • 195
  • 530
  • 832
8
votes
1 answer

Why does Autofixture w/ AutoMoqCustomization stop complaining about lack of parameterless constructor when class is sealed?

When I use Moq directly to mock IBuilderFactory and instantiate BuilderService myself in a unit test, I can get a passing test which verifies that the Create() method of IBuilderFactory is called exactly once. However, when I use Autofixture with…
Jeff
  • 2,191
  • 4
  • 30
  • 49
7
votes
1 answer

Jest snapshot failing: val.getMockName is not a function

I'm trying to set up a snapshot for a small react component but I keep getting the following error TypeError: val.getMockName is not a function it('renders correctly', () => { const wrapper = renderer.create(
7
votes
3 answers

AutoData Theories with AutoFixture using manual fakes

Given this system to test: public class MySut { private readonly IHardToMockDependency _hardToMockDependency; public MySut(IHardToMockDependency hardToMockDependency, IOtherDependency otherDependency) { …
TrueWill
  • 25,132
  • 10
  • 101
  • 150
7
votes
1 answer

AutoFixture.AutoMoq: set value to read only property

I use AutoFixture with AutoMoq. I try to create a fake instance of a class which has a property with a getter but without a setter. I expect AutoFixture to configure the mock so it will return the given value even there is no setter. My code is…
HerrLoesch
  • 1,023
  • 1
  • 13
  • 24
6
votes
1 answer

How can you use Lazy<> with AutoMock (Moq)

We are using Autofac.Extras.Moq.AutoMock. Now I have a constructor dependency using Lazy<> public MyService(Lazy myLazyDependency) {...} to test MyService we need to mock the Lazy. I am trying this…
dampee
  • 3,392
  • 1
  • 21
  • 37
6
votes
3 answers

Is the use of Auto Mocking containers good or bad practice?

I've recently been working on a project that has started to get fairly dependency heavy and have been exploring the idea of using an AutoMocking container to clean up my tests a bit and make them less brittle. I've heard arguments against using…
levelnis
  • 7,665
  • 6
  • 37
  • 61
5
votes
1 answer

How to auto-mock a container (e.g. IList) in MOQ without extensions/contrib

i wonder if it is possible to auto mock a container in MOQ without any additions to the MOQ lib. I am having problems finding a clean way to automock an IList. Thanks in advance!
zhengtonic
  • 720
  • 12
  • 25
5
votes
1 answer

When setting up a custom AutoDataAttribute for auto mocking, what's the proper syntax to tell AutoFixture to ignore all recursive structures?

I have xUnit/Moq/AutoFixture successfully working together so that I am auto mocking objects via test method input parameters. I created a custom [AutoMoqData] attribute which I use on every test. Here's the code for the attribute: using…
Andr
  • 1,043
  • 4
  • 13
  • 15
5
votes
2 answers

Automocking with LightInject plus Nsubstitute, how?

I am new to both libraries and before committing to their usage on a large project I need clarification on my options for low-code effort automocking in my unit tests. After spending some time on Google I have concluded that, unlike some other…
camelCase
  • 1,549
  • 2
  • 16
  • 28
5
votes
1 answer

CMake and Qt5 AUTOMOC error

I have a project which uses Qt5 and I have a CMakeLists.txt file that I use for creating the Visual Studio Solution. This is an excerpt of my CMakeLists.txt cmake_policy(SET CMP0020 NEW) set(CMAKE_AUTOMOC ON) find_package(Qt5 REQUIRED COMPONENTS…
Maverik
  • 2,358
  • 6
  • 34
  • 44
4
votes
3 answers

Auto mocking container for Windsor and Rhino

I am want to do automocking with Windsor so that I can do something like _controller = _autoMockingContainer.Create(); There used to be a Windsor auto mocking container in Ayende's Rhino libraries. But that…
Dan
  • 29,100
  • 43
  • 148
  • 207
1
2 3 4 5