Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [mocks]

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.

24
votes
2answers
4k views

Go on, mock my IDE

Because of the coupling with the VBIDE API (the extensibility library for the VBA IDE), unit testing the rubberduck refactorings, inspections and quick-fixes has been pretty much impossible, at least ...
11
votes
2answers
2k views

Mocking socket calls in C++

Explanation I'm trying to get better unit test coverage of my server. I needed to mock out some system libraries (I could not find anything that worked easily for C++). Because I did not want to do ...
10
votes
4answers
2k views

BigInteger formatting for endless tower defense game

I am working on an endless tower defense game in Unity. To keep track of money, damage, hitpoints and stuff like that I will be using BigInteger, which can ...
9
votes
1answer
3k views

Mocking UserDefaults in Swift

In my application, I am using UserDefaults to save some data. I also started writing tests for testing my application code. At one place I stuck where I wanted to ...
8
votes
2answers
248 views

Building an IDE, block by — er, mock by mock

The opening sentence of an answer I received in my previous post snowballed, and led to completely ditching the previous approach. Mocking my IDE with a MockFactory ...
7
votes
2answers
737 views

Mock/Stub out filesystem in F# for unit testing

I'm looking to do some basic verification testing on my functions that write to the filesystem. I took a hint from here on how to mock out the filesystem using an interface, but I'm kinda bummed on ...
7
votes
1answer
179 views

Monkeypatching __builtin__ in tests for mocking

I'm testing a little magic behaviour of my script that automatically reads from ~/.ghtoken to do automagic authentication on GitHub API requests. I want to test ...
6
votes
1answer
2k views

Using a factory class for TextWriter than can be stubbed/mocked

This is my factory class: ...
6
votes
1answer
2k views

Testing an abstract class

I started writing a set of tests for my SageContextBase class, which needs to be abstract because the client code must derive ...
6
votes
1answer
3k views

Ugly code unit testing with PHPUnit and Doctrine2 (an ORM)

I am trying to unit test a small class that I consider part of the "business-logic" layer of my project. It mostly just interact's with Doctrine's entity manager and a couple of entities with a many-...
6
votes
1answer
338 views

Unit test for a CreateUser() method using JustMock lite

I'm new to unit testing and have created a unit test for a create user action method and it's passing the test. I'm not sure if this is the right way to unit test a create method. This is my test ...
5
votes
1answer
15k views

Unit testing HTTP requests

I would like to unit test my web requests, so on top of my head I came up with the solution below. Since it seems to be working fine, I'm posting it on this site. Though it doesn't feel very dynamic, ...
5
votes
3answers
10k views

Unit testing a servlet in a meaningful way

I have to write a unit test for the method processRequest in the servlet below and I'm wondering if: It just shouldn't be done. The class should be rewritten / ...
5
votes
1answer
262 views

Mock user table class

I've just created my first tests using mock classes. So far my tests are running much faster and now I guess I'm solely focusing on a single class (in this case I'm testing UserTable and mocking the ...
5
votes
1answer
1k views

Testing file IO errors in python

Below is a simple class with two methods: the first calls open() to read in a file. The second calls the first method and does error handling. There is also a ...
5
votes
1answer
128 views

Mocking config data in JavaScript unit tests

I'd really like someone to sanity check my approach for unit testing the summarise() function and mocking its dependencies. Background Each option has a set of ...
4
votes
2answers
753 views

Fake utcnow for the pytest

I want to create a pytest with a fake utcnow, but also I need to preserve the functionality of all other datetime methods. ...
4
votes
1answer
1k views

PHP wrapper around an API - best practices

Here's a PHP wrapper around a public OAuth2 REST API. I would love to hear your thoughts and comments. Testing was a bit frustrating since I tried for my first time. Not sure if I have done the ...
4
votes
1answer
128 views

Testing a Pivotal API request client using lots of mocking

I have a class that is all about doing HTTP requests, and logging (in file system & database). It's only using 3 dependencies to do these things, so I'm fine with the code so far. Here it is for ...
4
votes
2answers
4k views

Using Mockito to verify that an object is saved

We've been reviewing some legacy code and have found differences in the preferred approach to how to write tests using Mockito. Both the following tests pass but which one is better and why? ...
4
votes
1answer
62 views

Unit Testing and good use of matchers

I been having discussion with colleagues recently about good use of matchers. Consider the following sample: ...
3
votes
2answers
157 views

Mockable clock meeting std::chrono TrivialClock requirement and interface

I'm using the time for e.g. ping and timeout calculation as well as animations in a game. So my (big) codebase uses std::chrono::steady_clock::now() in many places. ...
3
votes
2answers
716 views

Unit Testing of parser method using pytest

This is my first time using pytest. All feedback for this test case is much appreciated. ...
3
votes
2answers
239 views

Unit test for a method that adds tweets to a database

I have a class which inserts a list of tweets to a database table and also inserts the tweet's key with the associated filter's key to a many-to-many table. I am testing the sole public method of this ...
3
votes
1answer
510 views

Python unittest.mock.patch.object context manager

I want to test my core of handler, so I wrote this: ...
3
votes
2answers
143 views

PHPUnit test for a PaymentMethodRuleManager

The following code snippet is about adding rules that filters Payment Methods listing to customer, for email we provide 4 different types of payment methods, but we do show them depending on some ...
3
votes
1answer
726 views

Using mocking to test that a Django view renders as expected

I have a Django view that ends with this... return render(request, 'define/see_all.html', context) I have mocked the render function and ...
3
votes
0answers
39 views

Jest unit test that handles a wrapped Promise

I've wrapped an imported function (a promise) and attempted to write unit tests that bring my codebase to 100% coverage. ...
2
votes
1answer
250 views

How to test “verification flow” code? would you test this at all?

I want to write unit-test to my code. However, while writing it, it seems all I can verify is that one method or the other were called once. My class is a manager that execute verification flow. It ...
2
votes
1answer
55 views

Mockable adapters

The inspiration for this question comes from a talk by IanCooper; in particular, this remark: Never mock somebody else's interface... you want to mock your abstraction of how you call the third ...
2
votes
1answer
111 views

Mocking an F# primality tester

I would like to ask 2 questions about the modularization of an F# file. The code is just a working example of prime factorization, but that's not the main topic. I have a main file (PrimeFactors.fs), ...
2
votes
1answer
467 views

Testing controller class using mockito mvc

I'm beginner java programmer and would like to ask you to take a look at my code. I wrote small rest service among with tests. Now I have to questions to ask. The test methods: ...
2
votes
0answers
23 views

Testing abstract SettingConverter with mocks

One of my frameworks uses the ISettingConverter interface as an abstraction for serialization. ...
2
votes
1answer
3k views

Mock Entity or DTO for unit tests [closed]

Is this good approach, to mock some domain object, for example javax.persistence.Entity, or DTO (data transfer object)? Below is ...
1
vote
2answers
722 views

Possible fake testing with Rhino mock

I'm new to Rhino mock and I would like to know if the test I did is not fake testing, as I've read a lot about it. Are there any improvements that need to be done? ...
1
vote
1answer
218 views

Is building a test instance from a mix of both mock and real objects OK?

I am new to android testing and would like to try start off in the correct direction, so I am trying to understand if this is the correct way to test a particular method or if there is some best ...
1
vote
1answer
897 views

State and Interaction based testing using jMockIt

I am new to jMockIt and so wanted to learn it. I thought of implementing a synonym servlet kata. The servlet takes a word as input and returns the synoyms of the words as a comma seperated string. The ...
1
vote
1answer
65 views

Prepare a cross-platform QT C-wrapper class for unit testing and mocking

The situation I recently started a cross platform QT project (arm, linux-x86, windows) that aims to interact with CAN-Bus hardware. I want to learn and get used to unit testing from scratch as good ...
1
vote
1answer
44 views

Testing a service that makes database calls, without a database

I'm working on a new service, for the past year I haven't needed to write tests from scratch. I've either been bug fixing, or adding features that require modification of tests, but not writing ...
1
vote
1answer
149 views

Unit testing needs only optional methods of protocol in Swift

I have a protocol which has quite more methods, it looks like: ...
1
vote
1answer
40 views

Testing class that transforms JSON into a spreadsheet

I am creating unit tests but the class uses objects that have long JSON. What can I do to improve the readability of this? In tests, only insert those JSON really needed for the test. The class I ...
1
vote
0answers
53 views

Testable filesystem Writer for logging, with log rotation

I want to implement a custom Writer that allows the native go logger to do log rotation, and I also wanted to be able to write tests for it. The general idea was ...
1
vote
0answers
529 views

Mocking protocol with class/static functions in Swift

I am using one of the open-source Objective-C keychain wrappers to store data in iOS keychain. For test cases, I have created protocol as: ...
1
vote
0answers
47 views

Testing a method which coordinates multiple objects

I have this class with one method, which uses three different objects to perform a task. ...