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
2 votes
0 answers
78 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 ...
Martin York's user avatar
  • 94.3k
1 vote
0 answers
52 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 ...
Martin York's user avatar
  • 94.3k
1 vote
0 answers
45 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 ...
Martin York's user avatar
  • 94.3k
2 votes
1 answer
45 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 ...
Martin York's user avatar
  • 94.3k
3 votes
1 answer
107 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 ...
Martin York's user avatar
  • 94.3k
6 votes
1 answer
193 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 ...
Martin York's user avatar
  • 94.3k
3 votes
1 answer
101 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 ...
Caridorc's user avatar
  • 27.4k
0 votes
1 answer
111 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 ...
Jir's user avatar
  • 201
2 votes
1 answer
448 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. ...
HariHaravelan's user avatar
0 votes
1 answer
88 views

First time writing tests (Service Layer)

Service class: ...
GodLike's user avatar
  • 51
3 votes
1 answer
111 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 ...
EmaPrn's user avatar
  • 31
1 vote
1 answer
75 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. ...
Arseni Mourzenko's user avatar
2 votes
0 answers
83 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 ...
barryodev's user avatar
  • 121
2 votes
1 answer
311 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: ...
muaz's user avatar
  • 121
2 votes
1 answer
432 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, <...
Olvin Roght's user avatar
2 votes
1 answer
703 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 ...
user232326's user avatar
5 votes
0 answers
157 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 ...
Matt's user avatar
  • 151
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, ...
gerrit's user avatar
  • 905
1 vote
0 answers
45 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 ...
vikingosegundo's user avatar
2 votes
0 answers
256 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 ...
Abuanac's user avatar
  • 21
1 vote
2 answers
168 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....
EresDev's user avatar
  • 121
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 ...
CJR's user avatar
  • 151
4 votes
2 answers
3k 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. ...
Brown Bear's user avatar
1 vote
1 answer
251 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 ...
darkmattercoder's user avatar
1 vote
1 answer
192 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 ...
mal's user avatar
  • 313
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. ...
Flamefire's user avatar
  • 241
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. ...
ilrein's user avatar
  • 161
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 ...
Loupax's user avatar
  • 219
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), ...
ntohl's user avatar
  • 123
3 votes
1 answer
47 views

Testing abstract SettingConverter with mocks

One of my frameworks uses the ISettingConverter interface as an abstraction for serialization. ...
t3chb0t's user avatar
  • 44.2k
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: ...
Denny's user avatar
  • 141
1 vote
1 answer
269 views

Unit testing needs only optional methods of protocol in Swift

I have a protocol which has quite more methods, it looks like: ...
D4ttatraya's user avatar
10 votes
2 answers
6k 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 ...
Martin York's user avatar
  • 94.3k
6 votes
1 answer
631 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 ...
Satvinder Singh's user avatar
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 ...
Yaroslav Boichuk's user avatar
1 vote
0 answers
757 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: ...
D4ttatraya's user avatar
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 ...
D4ttatraya's user avatar
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 ...
Dahab's user avatar
  • 149
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 ...
Steve Chamaillard's user avatar
2 votes
1 answer
767 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: ...
filemonczyk's user avatar
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 ...
Joff's user avatar
  • 263
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 ...
SJC's user avatar
  • 241
5 votes
1 answer
317 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 ...
joecritch's user avatar
  • 153
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 ...
Thijs Riezebeek's user avatar
3 votes
2 answers
265 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 ...
Aki K's user avatar
  • 1,329
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 ...
Mathieu Guindon's user avatar
4 votes
1 answer
78 views

Unit Testing and good use of matchers

I been having discussion with colleagues recently about good use of matchers. Consider the following sample: ...
npmaster's user avatar
8 votes
2 answers
1k 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 ...
koenmetsu's user avatar
  • 183
8 votes
2 answers
272 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 ...
Mathieu Guindon's user avatar
25 votes
2 answers
5k 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 ...
Mathieu Guindon's user avatar