« You're Already Using Continuous Flow (poorly) | Main | We're not ready for Kanban »

09/01/2009

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e54fb013da88340120a58c8716970c

Listed below are links to weblogs that reference Inline Assertion Templates for Eclipse:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Daniel Fireman

Nice point of view! I've never thought about assertion as an way to help debug and etc.

Thanks

Szczepan Faber

Interesting idea. I usually used java 'assert' for the same purpose (for example: assert false).

Using junit is interesting but I think your pattern might be difficult to implement in other IDEs. In IDEA, 'test' dependencies (like jUnit) are not visible for production code (like your User). (unless I'm wrong ;)

Ray

If I'm understanding correctly, I'd put the junit jar in my eclipse build-path, but not in the compile phase of my maven config. That way, the "temporary" inline assertion would break the build if it became non-temporary. Am I understanding the usage pattern correctly?

Ben Rady

Ray -- Yep. You can also add it to your maven config as a "test" scope dependency, use the maven eclipse plugin to generate your project, and get the same effect.

Cthulhu

Wouldn't it be simpler (especially for large projects) to have Cobertura (http://cobertura.sourceforge.net/) run over it? Or well, to check which methods are called by unit tests in any case - it can't figure out which tests call it with a null password parameter. But still.

Ben Rady


Right, the idea here is that coverage doesnt tell you the whole story. Inline assertions can help you detect cases in your code that are not tested, even if the code is 100% covered.

Darren

Seems to me you are just relocating your 'test' i.e. to your production code.

Assuming you aren't practising TDD, I feel this approach requires the same 'brain-storming' (i.e. hindsight, foresight, whatever) to think up the cases.

And so I still think 'assert' is better as it can be switched off (removed) by the compiler.

BR

Ben Rady


Darren, a critical difference between this technique and using the built in Java assertions is that these assertions are meant to be temporary. You add them, run your tests (or have Infinitest run them for you) and remove them as soon as you see the results. Theyre only in your code for a few seconds.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.