Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There are ordered sets, immutable sets... infinite sequences, lazy lists, sometimes collections are hairy to test.


If find that if I am trying to test values that are not 'fully realizable' (infinite, lazy, etc) there's typically a temporal aspect involved, and I have a 'mock clock and timer' implementation so that I can call a `time.advance(t)` from within my tests and time advances in my system under test. This works because (as OP also noted) I only use my own mockable abstractions for answering the question 'what time is it?' and for instructing the system 'call me back at time t'. The net effect being I can fully define the behavior of the system within an arbitrary window of time—and collect the resulting values or behavior into some data structure which encodes what happened and when, and then compare it against expected results.

Re immutable: the values you're getting from your system under test and the expected values you're constructing in tests should always be immutable!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: