tagged [mocking]
Mockito - @Spy vs @Mock
Mockito - @Spy vs @Mock I understand a spy calls the real methods on an object, while a mock calls methods on the double object. Also spies are to be avoided unless there is a code smell. However, how...
- Modified
- 18 Dec at 13:42
How do you mock out the file system in C# for unit testing?
How do you mock out the file system in C# for unit testing? Are there any libraries or methods to mock out the file system in C# to write unit tests? In my current case I have methods that check wheth...
- Modified
- 6 Jul at 14:42
NSubstitute: How to access actual parameters in Returns
NSubstitute: How to access actual parameters in Returns I would like to access actual parameter in NSubstitute `Returns` method. For example: Using NSubstitute what should I write in place of ``, or h...
- Modified
- 30 Jun at 11:50
Unit tests for code accessing ActiveDirectory
Unit tests for code accessing ActiveDirectory What's the best way to unit test an application accessing the ActiveDirectory and/or mock the dependencies to the AD? All the required types such as `Dire...
- Modified
- 18 May at 08:17
How can I "sleep" a Dart program
How can I "sleep" a Dart program I like to simulate an asynchronous web service call in my Dart application for testing. To simulate the randomness of these mock calls responding (possibly out of orde...
- Modified
- 26 Aug at 17:42
NSubstitute mock extension method
NSubstitute mock extension method I want to do mock extension method, but it does not work. How can this be done? --- ``` [Fact] public void Select() { var randomizer = Substitu
- Modified
- 12 Jan at 00:29
Mock a method for test
Mock a method for test Trying to mock a method that is called within another method. I want the method GetLastName to alwa
- Modified
- 15 Dec at 00:30
Mongodb unit testing in .NET
Mongodb unit testing in .NET I am trying to do tdd and use mongodb as database. But i cant resolve problem of mocking mongodb. Is there any ability to mock mongodb for unit testing in .NET? --- Update...
- Modified
- 9 Oct at 17:56
How to use NSubstitute to mock a lazy class
How to use NSubstitute to mock a lazy class The above code throws an exception. > The lazily
- Modified
- 14 Nov at 09:46
How to moq a static class with a static method (UnitOfWork case)?
How to moq a static class with a static method (UnitOfWork case)? I have these classes: ``` public static class UnitOfWorkSS { public static IUnitOfWork Begin() { return IoC.Resolve(); } } public...
Mocking objects without no-argument constructor in C# / .NET
Mocking objects without no-argument constructor in C# / .NET Is it possible to create a mock from a class that doesn't provide a no-argument constructor and don't pass any arguments to the constructor...
- Modified
- 10 Mar at 16:43
C# how to mock Configuration.GetSection("foo:bar").Get<List<string>>()
C# how to mock Configuration.GetSection("foo:bar").Get>() I have a list like following in config.json file ` ``` { "foo": { "bar": [ "1", "2", "3" ] } }` Configuration.GetSection("foo:b...
- Modified
- 6 May at 16:34
Are fakes better than Mocks?
Are fakes better than Mocks? I stumbled upon this open source project [Fake It Easy](http://code.google.com/p/fakeiteasy/), and I have to admit, it looks very interesting, however I have my doubts, wh...
- Modified
- 8 Mar at 09:26
phpunit mock method multiple calls with different arguments
phpunit mock method multiple calls with different arguments Is there any way to define different mock-expects for different input arguments? For example, I have database layer class called DB. This cl...
Asserting successive calls to a mock method
Asserting successive calls to a mock method Mock has a [helpful assert_called_with() method](https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_called_with). However, as fa...
SetupSequence in Moq
SetupSequence in Moq I want a mock that returns `0` the first time, then returns `1` anytime the method is called thereafter. The problem is that if the method is called 4 times, I have to write: Othe...
- Modified
- 9 Aug at 22:48
Return different instances for each call using rhino mocks
Return different instances for each call using rhino mocks I've got this code: When this is called four times, every time the same instance is returned. I want difference instances to be returned. I w...
- Modified
- 28 Jan at 13:30
Need some advice for trying to mock a .NET WebClient or equivalent
Need some advice for trying to mock a .NET WebClient or equivalent I've got some code which downloads some RSS feeds. I've been using `WebClient` or `Argotic.Syndication.RssFeed` libraries. I definate...
Mocking Static Methods
Mocking Static Methods Recently, I've begun to use [Moq](https://github.com/moq/moq4) to unit test. I use Moq to mock out classes that I don't need to test. How do you typically deal with static metho...
- Modified
- 28 Dec at 18:31
Using FakeItEasy, how to get the value set on a property on a fake?
Using FakeItEasy, how to get the value set on a property on a fake? Using FakeItEasy, I am trying to capture the setting of a property value on a fake object: ``` var myObject = A.Fake(); int saved = ...
- Modified
- 26 Oct at 18:57
Mockito test a void method throws an exception
Mockito test a void method throws an exception I have a method with a `void` return type. It can also throw a number of exceptions so I'd like to test those exceptions being thrown. All attempts have ...
Async methods return null
Async methods return null If I try to mock a type containing an `async` method such as : Then the mock's `Bar` method is returning null. I guess Moq is choosing `default(Task)` as default return value...
- Modified
- 2 Jun at 21:45
Using Moq to determine if a method is called
Using Moq to determine if a method is called It is my understanding that I can test that a method call will occur if I call a higher level method, i.e.: I want to test that if I call `SomeMethod()` th...
- Modified
- 28 Aug at 12:52
Moq property with protected setter
Moq property with protected setter I want to Moq next object: so that `new Mock().Bar` return `"Blah"`. How can I do that? --- throws > Failure: System.NotSupportedException : Invalid setup on a non-v...
- Modified
- 11 Sep at 19:14