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.

Filter by
Sorted by
Tagged with
3 votes
1 answer
70 views

C++ Mock Library: Part 4

Parts C++ Mock Library: Part 1 C++ Mock Library: Part 2 C++ Mock Library: Part 3 C++ Mock Library: Part 4 C++ Mock Library: Part 5 C++ Mock Library: Part 6 Description: In part 3 I described how I ...
4 votes
1 answer
159 views

Track and trace allocations

When testing or debugging allocator-aware objects, it can be useful to provide allocators that can provide insight into how they get called. The Tracing_alloc from ...
2 votes
0 answers
90 views

C++ Mock Library: Part 6

Parts C++ Mock Library: Part 1 C++ Mock Library: Part 2 C++ Mock Library: Part 3 C++ Mock Library: Part 4 C++ Mock Library: Part 5 C++ Mock Library: Part 6 Side Note: I will say the processes of ...
6 votes
1 answer
237 views

C++ Mock Library: Part 1

Parts C++ Mock Library: Part 1 C++ Mock Library: Part 2 C++ Mock Library: Part 3 C++ Mock Library: Part 4 C++ Mock Library: Part 5 C++ Mock Library: Part 6 Note: If you see an extra ...
3 votes
1 answer
120 views

C++ Mock Library: Part 2

Parts C++ Mock Library: Part 1 C++ Mock Library: Part 2 C++ Mock Library: Part 3 C++ Mock Library: Part 4 C++ Mock Library: Part 5 C++ Mock Library: Part 6 Removing redundant MOCK_SYS usage After ...
2 votes
1 answer
54 views

C++ Mock Library: Part 3

Parts C++ Mock Library: Part 1 C++ Mock Library: Part 2 C++ Mock Library: Part 3 C++ Mock Library: Part 4 C++ Mock Library: Part 5 C++ Mock Library: Part 6 Define normal use case patterns: The next ...
1 vote
0 answers
55 views

C++ Mock Library: Part 5

Parts C++ Mock Library: Part 1 C++ Mock Library: Part 2 C++ Mock Library: Part 3 C++ Mock Library: Part 4 C++ Mock Library: Part 5 C++ Mock Library: Part 6 Overview So brief overview: Part3 was the ...
3 votes
1 answer
122 views

End to End testing of user interaction in Rust

I am interested in any kind of possible improvement to this method of testing a Rust program with user interaction in an end-to-end manner (simulating user input and asserting a certain program output ...
0 votes
1 answer
127 views

Unit testing and alternative to mocking in Haskell

Let's say you have a simple pure function that applies a discount of 30% if the total price of a list of Items is over 30.00 (let's not delve into the fact that I'm ...
2 votes
1 answer
522 views

Basic Ticket booking code with Unit tests

I am going to run a session for a few other developers who are new to Junit, mocking, etc. I have designed a very simple application with classes and tests to demonstrate how to do unit testing. ...
0 votes
1 answer
92 views

First time writing tests (Service Layer)

Service class: ...
3 votes
1 answer
123 views

Abstract wrapper for fundamental types

I have created this interface as part of my C++ learning path. This post inspired me a lot. The idea is to use its concrete implementations to perform some actions before and after any change of the ...
1 vote
1 answer
82 views

How to make the initialization of the mocks more readable?

In an Arduino project, I'm using some code which is a slightly modified version of a public library. I made several modifications to it: I performed some minor changes I needed to make the code work. ...
5 votes
3 answers
14k 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 / ...
2 votes
0 answers
90 views

A terminal based atom feed reader written in golang

I'm a beginner trying to get a better understanding of golang so I decided to write an atom feeder that runs from the terminal. I am using the gofeed library to parse the atom feeds and the tview ...
2 votes
1 answer
321 views

Mockingbird c++ mocking framework

I have developed Mockingbird a mocking framework for c++, it depends on function injection, here is the code from the repository: ...
2 votes
1 answer
492 views

Universal class for proxifying poplib, imaplib and smtplib. Lame inheritance or mock or something else?

This is wrapper for POP3, POP3_SSL, IMAP4, IMAP4_SSL, <...
3 votes
3 answers
3k 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. ...
2 votes
1 answer
759 views

Testing a template function in GoLang using mocking - making it DRY & easy to follow

TL;DR I'm wondering how to organise test functions using mocks for GoLang drier & easier to follow. Function I have a template function that is very similar to ACF's getField: It take's in a ...
5 votes
0 answers
163 views

Using an extra mock simply to take advantage of the behaviour observation tooling

I'm writing integration for a project, but our framework doesn't provide any ability to inject dependencies, so I've written tests with a unit testing framework (GTest) and used a mock (GMock) in an ...
8 votes
2 answers
6k views

Mocking pathlib.Path I/O methods in a maintainable way which tests functionality not implementation

I have a function that constructs a path based on a function of inputs and creates the parent directory. When writing a unit test for this function, I want to mock the I/O part of the function, ...
1 vote
0 answers
46 views

Message handling: Should a test/spec do it?

I am currently implementing an app that uses an architecture based on features & usecases and message sending. Features are created with message handler passed in. To test the feature, a handler ...
2 votes
0 answers
275 views

C++ Sql-like base operating on csv files

I implemented very constrained trivial implementation of sql querries operating on user files (in csv format). Where possible i tried to use modern C++ features. The fancy goal is to serve MySql ...
3 votes
1 answer
47 views

Testing abstract SettingConverter with mocks

One of my frameworks uses the ISettingConverter interface as an abstraction for serialization. ...
1 vote
2 answers
185 views

PHP unit test to confirm that a validator is being called correctly

I have a Responder class whose prepare method takes an entity, checks it with a validator, and returns a response or errorResponse based on the results of validator....
6 votes
1 answer
1k 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. ...
3 votes
0 answers
1k views

Android+Firebase testing using Mockito

I have an interactor/usecase class in my application. My application follows MVVM architecture with interactor/usecases responsible for logic (e.g. get data from api-service, store in local-database ...
4 votes
2 answers
4k 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
2 answers
8k 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? ...
1 vote
1 answer
257 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
1 answer
309 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 ...
2 votes
0 answers
69 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 ...
3 votes
1 answer
1k views

Python unittest.mock.patch.object context manager

I want to test my core of handler, so I wrote this: ...
3 votes
1 answer
2k 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 ...
2 votes
1 answer
162 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), ...
6 votes
1 answer
634 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 ...
3 votes
2 answers
160 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 ...
10 votes
2 answers
7k 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 ...
1 vote
1 answer
271 views

Unit testing needs only optional methods of protocol in Swift

I have a protocol which has quite more methods, it looks like: ...
5 votes
1 answer
464 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
1 answer
328 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
1 answer
15k 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
0 answers
763 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: ...
9 votes
1 answer
6k 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 ...
4 votes
1 answer
137 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 ...
2 votes
1 answer
772 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: ...
6 votes
1 answer
3k 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 ...
10 votes
4 answers
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 ...
3 votes
2 answers
267 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 ...
6 votes
1 answer
5k 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 ...