Hello to all,
I'm new to the list and for sure not a long-time experienced developer, so feel free to let me know if I should look elsewhere for answers to my questions.
Since it's not always easy nor obvious (at least) for me to change my mind model from procedural to OO, I'm trying to define some rough heuristics to decide whether I'm "thinking" it's something that can be classified as an implementation detail or observable behavior that should be tested. Let me clarify that with an example:
Currently I have a bridge object that separates details about communication to a serial device via a 3rd party library (let's call it RS232Device) from an object that should be responsible of handling commands and responses at a more higher level (let's call it PlantController).
Let's say that I already defined by other unit tests that PlantController has a dependency on RS232Device for what concerns *sending* commands to it. Now I need to make my way back, from raw bits emitted from serial port to the plant controller.
Since code is asynchronous, a peer can receive responses by RS232Device by registering a listener to it. This is already done in main, since a previous acceptance test already set that link (Ruby code):
class Application
instrument = RS232Device.create serial_port
instrument.on_data method(:receive_data) # Here Application register itself as a listener
...
private
def receive_data(data)
# do something
end
end
Now I need to move receive_data() to PlantController, since that fits better the SRP principle and will help making the end-to-end pass.
What I'm trying to figure out is if I need to add a test in PlantController unit suite that checks PlantController register itself as a listener to RS232Device upon creation before rewiring components.
I feel that this would be a wrong thing to do, and that feeling (that I cannot formalize yet) is in some way supported by a smell in the test that should be written. The unit test suite for PlantController is as follows:
describe PlantController
before do
...
plant_controller = PlantController.new ...
end
it 'test something' do
# setup mock
# call PlantController method
end
To implement the above test, I would need to do something like this:
it 'listens for responses given by device' do
device = mock
device.expects(:on_data).at_least_once
new_plant_controller = PlantController.new device
end
Here's what I feel as a smell:
- I would need to duplicate the setup code currently handled in the before() call
- I won't "trigger" anything by calling a method on PlantController, just testing against constructor
Are these considerarions suggesting that I don't need to test this code because it is a detail on how PlantController is implemented? More generally, it is possible to define "testing code on the constructor" as an heuristic to decide something should be treated as an implementation detail?
I apologize for the verbosity, hope though that I'd been clear enough and that someone has an answer to dissipate the clouds that still reside on this kind of reasoning.
Thanks,
Stefano Zanella
I generally don't write comments as I consider them a code smell. But recently (in the last year) I've started writing comments explaining my thinking and possible future directions for anything I think I'll forget or that others will find useful. I've found it really helps. I've got a brain like a sieve and I was finding that I frequently ended up rewriting code I'd previously written because I couldn't remember the direction the design was going in. A real waste of time. The comments have almost completely stopped that, but they do cause a new problem: you have to resist implementing the design you're explaining in the comment.
David
--
--- You received this message because you are subscribed to a topic in the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/growing-object-oriented-software/4S5FOWeHt5U/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to growing-object-oriented-software+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
S
--
---
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriente...@googlegroups.com.
I generally don't write comments as I consider them a code smell. But recently (in the last year) I've started writing comments explaining my thinking and possible future directions for anything I think I'll forget or that others will find useful. I've found it really helps. I've got a brain like a sieve and I was finding that I frequently ended up rewriting code I'd previously written because I couldn't remember the direction the design was going in. A real waste of time. The comments have almost completely stopped that, but they do cause a new problem: you have to resist implementing the design you're explaining in the comment.
You received this message because you are subscribed to the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to growing-object-oriente...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and all its topics, send an email to growing-object-oriente...@googlegroups.com.
I've actually been using the tag FUTURE. I've reserved the tag TODO to mean "needs cleaning up". I try to keep TODOs to a minimum. Whereas FUTUREs are fine and about possible future directions, rather than the health of the design. Sometimes I use FUTURE instead of TODO for something that could be cleaned up but that I don't feel is worth the effort at the moment. I personally don't think all code needs to be beautifully designed.
I wonder if this would work best with a maximum TODO budget to stop the usual descent into chaos.
On 15 Apr 2013, at 20:52, Steve Freeman <st...@m3p.co.uk> wrote:I wonder if this would work best with a maximum TODO budget to stop the usual descent into chaos.
Or:$ crontab -l0 9 * * * TODO_COUNT=`grep -nr "TODO:" /code | wc -l` echo "You have "$TODO_COUNTS" todo(s) in your codebase" | mail whole...@example.com -s "TODO COUNT IS "$TODO_COUNTAnnoying enough? :-)
--
---
You received this message because you are subscribed to a topic in the Google Groups "Growing Object-Oriented Software" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/growing-object-oriented-software/4S5FOWeHt5U/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to growing-object-oriente...@googlegroups.com.