Skip to main content
9 votes
Accepted

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

I'm no professional when it comes to testing. But it looks like your code is a perfect example on non-test friendly code. And is why SRP, single responsibility principle is such a big thing. From my ...
Peilonrayz's user avatar
  • 44.6k
9 votes

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

Mocking system calls, especially those with side effects (mkdir()), is difficult and error prone. I would rather use a temporary directory for test purposes. This ...
etene's user avatar
  • 461
7 votes
Accepted

C++ Mock Library: Part 1

Macros are difficult Your code relies on macros, and macros are notoriously difficult to work with if you go beyond the simple #define CONSTANT and ...
G. Sliepen's user avatar
  • 69.3k
6 votes

Mockable clock meeting std::chrono TrivialClock requirement and interface

While I think the underlying idea is quite nice, the actual implementation and design has some issues. Wrong Abstraction Level Let's start with the less obvious one: How would you actually use ...
hoffmale's user avatar
  • 6,528
5 votes
Accepted

Fake utcnow for the pytest

According to this, subclassing datetime.datetime seems the way to go. There is no use for the str_2_time method though. You can ...
Maarten Fabré's user avatar
4 votes
Accepted

C++ Mock Library: Part 4

I only have some minor remarks on the implementation. There are 2 commented-out lines in there: ...
Mast's user avatar
  • 13.8k
4 votes
Accepted

C++ Mock Library: Part 2

Write it in C++ The script is something I would cobble together as well when I would start working out this problem. However, it is nice for rapid prototyping, but it's actually terrible. It's not ...
G. Sliepen's user avatar
  • 69.3k
3 votes

Jest unit test that handles a wrapped Promise

I think the test is ok. Remember what you're testing is this ...
Gonzalo.-'s user avatar
  • 141
3 votes
Accepted

Track and trace allocations

Missing thread-safety The default allocator is thread-safe, and custom allocators might also be. So for your allocator adapters to not destroy the thread-safety, you need to make sure you handle that ...
G. Sliepen's user avatar
  • 69.3k
3 votes
Accepted

How to make the initialization of the mocks more readable?

I think the last test case is illustrative because you've repeated in comments all the stuff that should have been in the code. Instead of: ...
Quuxplusone's user avatar
  • 19.7k
3 votes

Mockingbird c++ mocking framework

You make the code really hard to read: ...
Loki Astari's user avatar
  • 97.7k
3 votes

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

The thing is, there is not much to test in your code. You have added several abstractions to a simple statement: ...
alx's user avatar
  • 496
3 votes
Accepted

Mocking socket calls in C++

This is a worthwhile task - I'm a firm believer in maximising my opportunities for automated testing. It tends to increase my peers' respect for my code, as they know they are less likely to find ...
Toby Speight's user avatar
  • 88.4k
3 votes
Accepted

Swift: Mocking a REST API-request

The problem with the fetchPeople() method (and others like it) is that they are all virtually identical but every time you need to consume a new endpoint, you have ...
Daniel T.'s user avatar
  • 991
2 votes
Accepted

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

This answer doesn't particularly address your questions, but it does talk about some generic C++ stuff. To make this clearer, I'm going to divide it between 'Feedback' and 'Opinion'. Feedback When ...
Reinderien's user avatar
  • 71.1k
2 votes
Accepted

Testing a service that makes database calls, without a database

Something that stands out is that calling voMock.getFileName() on mocked instances will always return null as no mock response has been defined. So your validation ...
Samour's user avatar
  • 36
2 votes

Mockable clock meeting std::chrono TrivialClock requirement and interface

If you care about performance, you can use templates to provide arguments at compile time. Example ...
Hemil's user avatar
  • 121
2 votes

Mockable clock meeting std::chrono TrivialClock requirement and interface

The use of a singleton will limit your possibilities, as hoffmale's review points out. It completely prevents concurrent testing. However, you'll find that getting the Clock instance to the code ...
Toby Speight's user avatar
  • 88.4k
2 votes

Mocking socket calls in C++

This is pretty hard to pass through. I'd have to say if it works for you... . Two points, i have had good results when doing code generation rather than using my own regex expressions and string ...
Harald Scheirich's user avatar
2 votes
Accepted

Testing abstract SettingConverter with mocks

Design I would argue that this base class doesn't add enough state / operations to be a base class. Consider using a mechanism other than inheritance to accomplish boiler-plate fallback serialisation....
dfhwze's user avatar
  • 14.2k
2 votes

Fake utcnow for the pytest

Usually, I do: Separate module, for example utils.py, that contains: ...
Sergei Zobov's user avatar
2 votes
Accepted

C++ Mock Library: Part 3

I can see how this can simplify some tests. The code looks also quite clean. However, I'm a bit worried about whether you should go this way. Here's why: About testing how a function is implemented I ...
G. Sliepen's user avatar
  • 69.3k
2 votes

Abstract wrapper for fundamental types

Answers to your questions As you can see my first idea was to use a macro to create a skeleton for the implementation. [...] What do you think? I think this is a bad idea. Macros should be avoided ...
G. Sliepen's user avatar
  • 69.3k
2 votes

Unit testing needs only optional methods of protocol in Swift

There are plenty of approaches that can fix your problem. But the main issue is how you build your classes. So IMHO you should focus on that. Recommendation 1: You should build your classes with ...
qwerty's user avatar
  • 121
2 votes
Accepted

Unit testing and alternative to mocking in Haskell

You can untangle your promo function from the Item data type ...
Li-yao Xia's user avatar
2 votes

Basic Ticket booking code with Unit tests

First: there's no evidence that you've set up a sane directory structure for your project, nor any package declarations. I hope that you do have package declarations, that your main files go in ...
Reinderien's user avatar
  • 71.1k
1 vote

End to End testing of user interaction in Rust

What you probably want to do is move from unit test to integration tests. That is, test your binary as a whole. Put your tests in tests/*.rs. You can use the ...
Winston Ewert's user avatar
1 vote

First time writing tests (Service Layer)

The test looks good. except that you do not have to initialize the UserService again inside the Test like below, since ...
HariHaravelan's user avatar
1 vote

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

Iteration for type_, (default_port, before_connection) in DEFAULT_SETTINGS.items(): doesn't necessarily need a for / break: an ...
Reinderien's user avatar
  • 71.1k

Only top scored, non community-wiki answers of a minimum length are eligible