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 ...
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 ...
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 ...
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 ...
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 ...
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♦
- 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 ...
3
votes
Jest unit test that handles a wrapped Promise
I think the test is ok. Remember what you're testing is this
...
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 ...
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:
...
3
votes
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:
...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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....
2
votes
Fake utcnow for the pytest
Usually, I do:
Separate module, for example utils.py, that contains:
...
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 ...
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 ...
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 ...
2
votes
Accepted
Unit testing and alternative to mocking in Haskell
You can untangle your promo function from the Item data type
...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
mocks × 65unit-testing × 47
java × 15
c++ × 14
c# × 9
python × 8
php × 6
beginner × 4
swift × 4
junit × 4
phpunit × 4
go × 3
wrapper × 3
javascript × 2
object-oriented × 2
c++11 × 2
json × 2
f# × 2
rubberduck × 2
integration-testing × 2
protocols × 2
just-mock × 2
python-3.x × 1
sql × 1
design-patterns × 1