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.
0
votes
1answer
94 views
How can I mock this architecture?
This is not a very general question, so it may not exactly be appropriate here, but I could sure use a suggestion if you have one:
I have an object containing a dictionary keyed off of an enum, ...
0
votes
0answers
50 views
when would you write static method as it avoid a “seam” for testing [duplicate]
when would you write static method.
I used to write it in utils classes where all the methods are static and work state-lessly on arguments only.
But now I know it blocks from creating a seam in ...
0
votes
1answer
86 views
Should I write a unit test to this?
Given the following pseudocode:
List dohList = new List();
Foo foo = A.getFoo();
if ( foo != null ) {
Bar bar = foo.getBar();
if ( bar != null ) {
FooBar fb = bar.getFooBar();
...
-1
votes
1answer
82 views
Create fake HTTP server to simulate an API for testing
I'm looking to mock responses from an external API service that returns JSON during live events.
The first response would contain (fake) events that have happened up to time X, the second response ...
0
votes
0answers
33 views
Populate faked context for unit testing WPF ViewModels using entity framework
We're developing an entity framework based application which has about 20 different entities, with quite a lot of connections of various types (one-many, many-many etc) between them. Each entity also ...
6
votes
3answers
746 views
How to unit test code that downloads a file from a github repo
This is my solution's structure:
Storage.csproj
> FileDownloader.cs
> GitHubProvider.cs (implements IStorageProvider)
> IStorageProvider.cs
Storage.Test.csproj
> ...
0
votes
2answers
86 views
Is a mocking framework useful if I'm unit testing a repository/database? [duplicate]
I'm trying to improve my testing skills. I frequently hear about mocking framework to build fake objects (as far as I understand). Right now I need to test my repository (the usual add, remove, update ...
0
votes
0answers
44 views
Mocks and Stubs - Classes and methods? [duplicate]
I'm trying to get a high level understanding of mocks and stubs.
My language/frameworks are ruby, rails, rspec, jasmine
I heard this very high level definition:
Mocks are used to represent objects ...
1
vote
1answer
69 views
Using Mockito.reset
I've just read a lot of arguments against using Mockito.reset and can't make much sense of it. Put differently, I agree in general, but there's always a case which looks like using reset is useful or ...
1
vote
1answer
68 views
Question about mocking externals [duplicate]
at company we're developing quite a big project and we're arguing at the testing strategy. The question is: should all of the tests be executed in isolation of external services like database or APIs ...
0
votes
1answer
85 views
How to write a good mock for testing
I code in Python and I'm starting to use the Mock library.
Although I've read through all of the documentation, something that I'm finding hard to understand is 'What makes a good mock'.
For ...
0
votes
1answer
108 views
How do you detect lying Stubs/Mocks?
Consider this piece of code from the PHPUnit manual(I'm using PHP only as an example):
class StubTest extends PHPUnit_Framework_TestCase
{
public function testStub()
{
// Create a ...
1
vote
2answers
211 views
How to unit test without mocks and not be tied to a concrete implementations of an interface
I consider myself to be a 'mockist' on the 'mockist' vs 'classicist' debate, but I am trying to understand the other point of view.
Imagine I have this class, where a concrete instance of IDependency ...
0
votes
2answers
86 views
Should we write a unit test for class that call another class that have code written
Suppose that there are two class 'A' and 'B'
'A' has a lot of nested conditions that have all unit test covered.
'B' has a property that will call class 'A' and return value according to the result ...
0
votes
4answers
191 views
What does “mockable” mean?
I came across this term when looking into PHP's "traits" (which are apparently bad, since, among things, they're not mockable), but I can't really find a definition for this "mockability". It might be ...
5
votes
3answers
137 views
Using mocks to set up object even if you will not be mocking any behavior or verifying any interaction with it?
When building a unit test, is it appropriate to use a mocking tool to assist you in setting up an object even if you will not be mocking any behavior or verifying any interaction with that object?
...
1
vote
2answers
448 views
Testing C# Eventhandler Subscription
I want my unit tests to be able to verify that some events were subscribed or unsubscribed at specific points. Currently, I see two options.
VerifiableEventHandler
Each client subscribes using the ...
3
votes
3answers
243 views
how and should I 'unit test' an entire package?
I'm still learning to be good about doing unit level testing, as I've always been a little sloppy about only doing functional testing in the past, so I want to double check I'm doing this 'right'.
I ...
15
votes
6answers
821 views
From a TDD perspective, am I a bad person if I test against a live endpoint instead of a mock?
I follow TDD religiously. My projects typically have 85% or better test coverage, with meaningful test cases.
I do a lot of work with HBase, and the main client interface, HTable, is a real pain ...
2
votes
4answers
256 views
Test Doubles, Mocks and Stubs - when not to use & why, for Ruby, Rspec
I've learned about mocking and stubbing and I've seen how they can help me create great test suites that run blindingly fast and thus speed up my development process hugely.
However I've also seen ...
2
votes
3answers
712 views
Mocking static methods
Having recently returned from a Test Driven Development (TDD) course I had the following thought.
While writing unit tests using Mockito we came up against of the problem of mocking static methods. ...
0
votes
2answers
114 views
Using interfaces as part of encapsulation
I'm creating interfaces for a number of our existing classes for mocking reasons. Many of these classes also have package scope methods as an attempt to give some level of encapsulation by ensuring ...
4
votes
6answers
913 views
Are HSQLDB unit tests an anti pattern?
HSQLDB is great. It (also) has an embedded mode (no dedicated server needed), which allows for quick prototyping of stuff like Proof of Concepts, and it can also be great in production-ready ...
1
vote
2answers
174 views
TDD - Making assertions about C# Expression trees
How would you unit test the PerformUpdate method in the sample below? This is a (very) simplified version of some code that performs updates against a database where the schema is dynamic and ...
1
vote
3answers
1k views
How to use mock objects [C++] without passing them as arguments to functions
I'm in the process of integrating a Unit Testing Framework for an existing code base in C++. I've zeroed down on CxxTest, but as it turns out we can use other Mocking Frameworks (like googlemock) in ...
6
votes
3answers
1k views
How to mock method with hard coded object?
I am working on an application which have multiple layers. Data access layer to retrieve and save data from data source, business logic to manipulate data, user interface to show the data on screen.
...
2
votes
1answer
714 views
How to unit test a web client?
I am having a lot of trouble understanding how to unit test my web client.
I have just finished a project using TDD for the first time - this project hd no external dependencies such as API calls or ...
2
votes
5answers
140 views
Should mock objects for tests be created at a high or low level
When creating unit tests for those other objects, what is the best way to create mock objects that provide data to other objects. Should they be created at a 'high level' and intercept the calls as ...
5
votes
1answer
256 views
How much mocking is “just right?”
I titled the question jokingly because I'm sure that "it depends," but I have some specific questions.
Working in software that has many deep layers of dependency, my team has become accustomed using ...
0
votes
1answer
132 views
Method visibility for testing partial mocks
I'm currently writing unit tests to test behavior of a method and would like to partially mock the methods calling injected properties. For example:
public void doSomething() {
int complicatedInt ...
2
votes
1answer
220 views
Mocking complex data operations in integration tests
We have some problems figuring out how to mock complex data and operations on it.
First the problems with generating complex data:
In one of our components we have really complex data structures ...
0
votes
2answers
385 views
when to mock in unit testing [duplicate]
I am trying to write unit tests in javascript for an application made in nodejs. What I want to know is -
Say there is a class Vehicles which is dependent on another class Roads.
Should I mock the ...
3
votes
2answers
381 views
What is the most appropriate testing method in this scenario?
I'm writing some Objective-C apps (for OS X/iOS) and I'm currently implementing a service to be shared across them. The service is intended to be fairly self-contained.
For the current functionality ...
3
votes
1answer
120 views
Stubbing and mocking boundaries
Suppose I'm building a JSON API and would like to include an endpoint that returns a list of recently created posts. Somewhere in my system is an existing Post model with the following test:
create ...
1
vote
3answers
402 views
Unit-testing functions without business logic (only checks) [duplicate]
My team is trying to find out the best way to test one of our components; the main scope is to check if the user/actor has the right to complete the operation requested. The component is formed by ...
14
votes
3answers
995 views
Brittle unit tests due to need for excessive mocking
I've been struggling with an increasingly annoying problem regarding our unit tests that we are implementing in my team. We are attempting to add unit tests into legacy code that wasn't well designed ...
2
votes
2answers
197 views
Mock up class object
For example I have class ItemDownloader which has method downloadItem. This method creates instance of another class - Download to perform actual downloading.
Question is: I want to test ...
9
votes
2answers
7k views
Is this an appropriate use of Mockito's reset method?
I have a private method in my test class that constructs a commonly used Bar object. The Bar constructor calls someMethod() method in my mocked object:
private @Mock Foo mockedObject; // My mocked ...
2
votes
1answer
172 views
Unit Testing Open Source projects that require keys for api calls
What's the recommended method for setting up tests on code that requires a private key to make calls to external web services?
Full on mock objects or is there a way of distributing open source unit ...
3
votes
2answers
177 views
Is it okay to mock multiple objects in one class?
For developers with extensive experience using mocks, is it okay to mock multiple objects in one class (ie satisfy multiple interfaces) or is this not recommended?
I am wondering because mocks are ...
10
votes
2answers
245 views
How would type errors be detected while creating mocks in a dynamic language?
The problem occurs while doing TDD. After a couple of test pass, the return types of some class/module change. In a statically typed programming language, if a previous mocked object was used in the ...
4
votes
2answers
97 views
How deep should we dive into testing different layers
We use Drupal 7 as our base CMS tool.
For one specific product, something like an ERP, we've created sort of a non-drupal layer, to keep our specific business code in.
It would be something like ...
8
votes
3answers
1k views
Mocking concrete class - Not recommended
I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended.
Here some sample code of a unit-test for the ...
2
votes
2answers
226 views
Returning a mock object from a mock object
I'm trying to return an object when mocking a parser class. This is the test code using PHPUnit 3.7
//set up the result object that I want to be returned from the call to parse method
...
6
votes
7answers
1k views
Is mocking for unit testing appropriate in this scenario?
I have written around 20 methods in Java and all of them call some web services.
None of these web services are available yet. To carry on with the server side coding, I hard-coded the results that ...
3
votes
1answer
1k views
How to unit test image processing code?
I'm working in image processing (mainly OCR) and I wonder how I should integrate unit tests in my development.
I'm already using unit tests for more "common" type of code but when dealing with image ...
7
votes
1answer
288 views
Who should initialize dependencies in a TDD application?
I'm trying to learn implementing TDD with mocking/fake objects. One of the questions I have is how to initialize a dependency in an application which implements TDD? An example from this article
...
7
votes
4answers
373 views
How would a new language look if it was designed from scratch to be easy to TDD?
With the some most common languages (Java, C#, Java, etc) it sometimes seems that you are working at odds with the language when you want to fully TDD your code.
For example, in Java and C# you will ...
4
votes
1answer
187 views
What is a “behavior rich object” and why would it be advantageous?
I am referring to the article Mocks aren't Stubs by Martin Fowler. When naming cases when he think "mockist" TDD will be advantageous, he said
It's particularly worth trying if you are having ...
7
votes
5answers
665 views
TDD: Mocking out tightly coupled objects
Sometimes objects just need to be tightly coupled. For example, a CsvFile class will probably need to work tightly with the CsvRecord class (or ICsvRecord interface).
However from what I learned in ...