13 votes
Accepted

Mocking UserDefaults in Swift

So first, as CAD97 rightly points out, if you simply define your protocol as identically matching the methods from UserDefaults you intend to use, then making ...
nhgrif's user avatar
  • 25.3k
13 votes

BigInteger formatting for endless tower defense game

Naming Interfaces are usually named starting with a capital I in .NET. ScientificFormatter Here you have ...
Heslacher's user avatar
  • 50.4k
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
  • 43.3k
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
6 votes

BigInteger formatting for endless tower defense game

This isn't a full review, it's just a couple of initial thoughts: Unlike Java, Interfaces in C# are usually prefixed with 'I', so BigIntegerFormatter becomes <...
forsvarir's user avatar
  • 11.6k
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,488
6 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
  • 55.4k
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 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
  • 55.4k
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
  • 486
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

Testing a Pivotal API request client using lots of mocking

First of all, Bravo for writing unit tests! Secondly, Bravo for doing it in PHP! Seriously though, I don't see enough people doing this type of testing. What you're running into is referred to as ...
xDaevax's user avatar
  • 1,171
3 votes

Testing file IO errors in python

The design of the readconfig() function is seriously problematic. It makes no sense to convert caught exceptions into data, as if the file literally contained the ...
200_success's user avatar
3 votes

Mockingbird c++ mocking framework

You make the code really hard to read: ...
Martin York's user avatar
3 votes

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.4k
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
  • 55.4k
2 votes

Unit test for a method that adds tweets to a database

Disclaimer: I'm not a huge fan of mocks. Some issues I see with the approach: The fixture setup is quite complicated, involving a lot of mocks. It's a lot to read. Using loops in test methods is a ...
janos's user avatar
  • 111k
2 votes
Accepted

Testing an abstract class

Just a couple of things. You repeat this set up in every test. ...
RubberDuck's user avatar
  • 30.8k
2 votes
Accepted

Mocking config data in JavaScript unit tests

I agree with point number 2, just passing in the config is better (i.e. dependency injection). You could do it like this: ...
Magnus Jeffs Tovslid's user avatar
2 votes

BigInteger formatting for endless tower defense game

This: ...
Risky Martin's user avatar
  • 1,611
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

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
  • 74.9k
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
  • 13.9k
2 votes

Fake utcnow for the pytest

Usually, I do: Separate module, for example utils.py, that contains: ...
S. Zobov's user avatar
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
  • 61.9k
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
  • 74.9k
2 votes

Unit test for a CreateUser() method using JustMock lite

I think you are not testing everything. The API should create a user but the only thing you assert is the ActionResult ...
t3chb0t's user avatar
  • 44.3k
2 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.3k

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