Time in C++: Once More About Testing
sandordargo.com·1d·
Discuss: Hacker News, r/cpp
🔬Static Analysis
Preview
Report Post

I planned to finish this series this week. But then I realized that there are still a couple of important things about testing that I haven’t written about yet. We already touched on the problem of testing when we discussed system_clock, but it definitely deserves a bit more attention.

We said that as it’s not really possible to mock system_clock, it’s a good idea to wrap your clock and pass that wrapper into your functions. That way, in tests, you can substitute it with a fake implementation where you control the returned time.

Let’s first look at the problem in a bit more detail, and then walk through a few possible solutions.

The problem of time and testing

Let’s say you have a function that takes …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help