Questions tagged [mocking]
Mocking and faking are ways to isolate code or components to ensure that unit tests run against the testable unit of code only without actually utilizing other components or dependencies of an application. Mocking differs from faking in that a mock can be inspected to assert the results of a test.
200 questions
0 votes
4 answers
233 views
Avoid Test duplication if a function created via TDD has an implementation detail that is later used in other functions
Lets say I have an API with two functions: CreateNewMachine(CreateMachineCommand createMachine); EditExistingMachine(EditMachineCommand editMachine); The internal logic of both functions should be ...
-3 votes
1 answer
145 views
Mock an API for development purpose (no testing)
If I want to implement a connection from my software to an API, which is documented but not accessible yet, what is a common way to imitate the API until it is available? My first idea was to mock the ...
3 votes
2 answers
688 views
.Net 8 XUnit: Should my tests use real data or how to mock MySql with CQRS?
I'm creating tests for our .Net 8 API. We use MySql for data storage and CQRS pattern for queries. In my personal opinion, I shouldn't use the real database for testing, because you will use an ...
1 vote
1 answer
218 views
Benefits of resolving dependencies with IServiceCollection and IServiceProvider for Unit Tests instead of inheriting mocks from a base test class
Articles such as this point out some of the pitfalls of manually instantiating dependencies in UTs, while showing some of the benefits of doing it, instead, with the .NET's dependency container by use ...
-1 votes
1 answer
747 views
Alternatives to using mock libraries such as Mockito in unit testing
Typically, when writing unit tests I tend to need to stub out collaborators and also mock some behavior in one or more of the collaborating objects. Say if I am testing a Service that is using a Dao, ...
1 vote
1 answer
172 views
How do I mock API responses with security in mind?
My team and I are beginning to mock our API responses in our iOS app so we don't have to worry about our backend being up when testing. I have conditional compilation directives based on the ...
1 vote
3 answers
189 views
Isolate or Redundant Test?
I have lots of code like the following. An "Entity" type that has some numerical properties. To be able to reuse the arithmetic I write the arithmetic functions against an interface. I use ...
-1 votes
3 answers
138 views
Code Coverage and Unit Tests nomenclature [closed]
About tests: I have the following view on nomenclature: Unit tests are the kind of testes where you have a function ExtractBacon, where there is a function with an entry parameter Pig and a return of ...