Go...
Welcome
Feeds
On unit testing
Posted by ccondit on 12/1/06 @ 9:10 AM :: Updated by ccondit on 12/1/06 @ 9:11 AM
Tags ::

Unit testing is something that I agree with in principle, but seem to have a problem with in practice.

I haven't posted anything here for a couple of weeks now, partially due to the holidays in the U.S. as well as work, but mainly because I've been busy writing unit tests for the site. Yes, I know, you're supposed to do that before you write your code, but I'm lazy and... well, I'm just lazy.

But, better late than never I suppose. I'm approximately 60% done writing the test cases, and in the process have an internal CruiseControl server set up to tell me just how cool I am that my unit tests pass. :)

Interestingly, I am starting to see the value of writing tests first. There is a large body of code that I have written for this project that while it is documented well and fairly clean, I find myself not knowing precisely what a method's constraints and side effects are (which is of course very important when writing unit tests). Consequently, the tests I'm writing now are probably not as complete as they should be.

Do you write unit tests? How good is your code coverage?

My Nickel on unit tests
Posted by Jeff Kamp on 12/3/06 @ 7:41 PM :: #7
I'm a big fan of unit testing. Where I work, we end up creating fairly large and complex systems (at least, in my opinion). If we only did system-level testing, the testing would take forever. However, since we're able to do unit-level testing, we're able to test each module individually and at the system-level, we only have to worry about everything playing nice together.
Welcome
Posted by ccondit on 12/7/06 @ 5:03 PM :: #8
It took me a few minutes to figure out who was posting, but I knew I'd seen that website before.

Thanks for stopping by, "Jeff". :)

P.S. I've really got to get a comment-notification system going... I didn't notice for almost a week that there was a new comment here.

P.P.S. Your 'secret identity' is safe with me.
Nothing to do with Unit Tests
Posted by Gaurav on 12/10/06 @ 7:19 AM :: #9
Hello Craig,
Sorry for posting a non-relevant comment here. There was no other contact info available for me to contact you.

I have seen that you have open sourced the code for this website. Incidentally, i was about to start work on a Blog Creation Tool. I think, your website's code is quite similar to what i am looking for.

If you can provide me a very brief desc about the code available in you subversion repos., that would help me jump start. If you have a note on the technical architecture used for the website, that would be a plus.

I really appreciate your effort in open sourcing your code. When java frameworks change every few months, it helps to start with something that is working.

Thanks in advance for your help.

Cheers,
Gaurav
Imagine yourself as someone picking up another's code
Posted by cwilkes on 1/26/07 @ 12:00 AM :: #19
and that's when the junit lightbulb will turn on. What's even better is when you see junit tests checked into source control so you can see the evolution of the other developer's thinking / finding out what's wrong.

Don't feel bad that you're writing the unit tests after you've coded. I rarely do until something blows up, which is about 5 seconds after I deploy the application for the first time. I write a test that duplicates the problem, making sure I get an error (there is a weird satisfication in causing a unit test to fail) and then fixing it. Now you're somewhat guaranteed not to run into that problem again.

Can you check in your unit tests into SVN? I'm looking at the code right now and I need more of a "story" on what each part is trying to do. That's another thing unit tests are good for, they show (and not 'tell' like the javadoc or other docs do) what's really going on.
Re: Imagine picking up another's code
Posted by ccondit on 1/26/07 @ 8:39 AM :: #22
You are absolutely right.

It's been about 2 months since I first posted this, and since then I've become a huge fan of JUnit. I've got around 150 unit tests written for this site, which unfortunately has delayed the next version somewhat.

The tests and all the code for the upcoming site are of course available in SVN. I won't spoil the surprise of what's coming, but you can always check it out yourself if you're impatient.
Can't see the tests in SVN
Posted by cwilkes on 1/26/07 @ 11:10 AM :: #23
Doh I was going off of the link on the http://randomcoder.com/articles/building-a-tag-cloud-in-java page which points to the 1.1.1 tagged release instead of trunk.

And I see that you've moved to maven so I'll scratch that off my list of things to offer help doing.
Comment on this article

Comments are closed for this post.