How disciplined are you with unit testing?

How much do you unit test?

  • What's unit testing?

    Votes: 0 0.0%

  • Total voters
    11

NathanRidley

New member
Jul 26, 2008
189
1
0
London, UK
I've been coding a long time (over 10 years) but it's only in the last few that I've really had much exposure to unit testing and only recently that I've been forcing myself to apply self-discipline and make sure I do it. I'm not all the way there yet, but am getting better at doing it consistently.

What about you fine people?
 


You'll make ALOT more money with proper unit tests in place. Takes about an additional 50% time to develop the same thing, but causes you much less stress, and you end up with far happier customers who don't bitch about you publicly, ruining your image in the process.

I have proper unit tests in place now finally, but didn't for quite a while. Reason being, the software was just changing too rapidly to make it worthwhile. For months, every week new functionality was being added, modified, etc. With each change, you have to go in and revamp the unit tests. Now that the software is solidified though, I've spent the time to put proper tests in place, and I'm sure it'll pay off in dividends.

It's actually one major mistake I made. Should have quit banging out functionality so quickly, and instead, concentrated on proper testing. Would have made for a much smoother journey for both myself, and all my customers. Again, just me being too nice for my own good. I want to take of customers and put a smile on their face, so tell them it'll be done within 72 hours, when instead I should learn to tell them tough shit, and to wait, so I can ensure everything is done 100% properly.
 
I do coding in java whenever i does i used to do proper Unit testing in Junit tool which makes me free in Integeration testing and it all depends on the persons.....

By the way in which platform u r talking about.
 
Most of my code is at 100% line coverage for the critical sections (external api, business critical stuff, etc) but for things like admin interfaces and non critical features I try and shoot for 80% coverage.

Recently spent about a week writing unit tests for an open source library we use because we found a huge issue that created massive downtime and directly impacted our bottom line :(
 
Since I posted this thread I've forced myself to code my current project using a 100% TDD approach. It's taking a little longer as a result, but I've noticed myself stomping on a lot of bugs now, rather than having users find them later. I think I prefer it actually, even though it can be a tad more tedious than the code-and-pray approach.
 
It really depends on what I'm doing and who I'm doing it for. If I'm doing something needed to be done yesterday and it's for myself. I'll hack out a quick prototype in a day or so and use it. I'll see if it's really something I find useful and if it is I'll redevelop it into something more sane and write unit tests along the way.

If it's something I'm going to sell or a contract I'll factor in the time it would take to write unit tests from the start and do them from the beginning.

There are some things that I don't unit test, because they're a waste of time. I'll generally skip unit testing a lot of controllers, because if they're made correctly the methods in them should be really really simple. I'll 100% test all models and libraries though. I'm also an avid user of mock objects for networking code, etc.
 
It's actually one major mistake I made. Should have quit banging out functionality so quickly, and instead, concentrated on proper testing. Would have made for a much smoother journey for both myself, and all my customers. Again, just me being too nice for my own good. I want to take of customers and put a smile on their face, so tell them it'll be done within 72 hours, when instead I should learn to tell them tough shit, and to wait, so I can ensure everything is done 100% properly.

Amen, but in the corporate world telling them "tough shit, I'm going to do it right" doesn't fly well. Executive boards can't conceptualize the cost of maintaining poorly built software. In my company (big healthcare) we've pulled out all the stops, going Mad Men marketing on their asses with projections and charts with unicorns and pretty colors. They look at them glassy eyed and say "well... can't we just double the development team and get it done twice as fast".

Some things will never change.
 
Amen, but in the corporate world telling them "tough shit, I'm going to do it right" doesn't fly well. Executive boards can't conceptualize the cost of maintaining poorly built software. In my company (big healthcare) we've pulled out all the stops, going Mad Men marketing on their asses with projections and charts with unicorns and pretty colors. They look at them glassy eyed and say "well... can't we just double the development team and get it done twice as fast".

Some things will never change.

Buy all of them copies of mythical man month.
 
Testing is one of those things that you just don't appreciate til you realize it saves your ass.

At any moment in Vim from any file in my app root, I can press <Comma>r and run the test suite or <Comma>f and run just the test for that file (if it exists). That instant feedback does wonders.

Code:
it "correctly handles a superficially comprehensive-looking example", ->
  url = "http://user:pass@foo.bar.lol.pauldiz.co.uk:3000/a/b/c/index.html?q=arg&hello=world"
  uri = domainatrix.parse url
  assert uri.auth is          "user:pass"
  assert uri.host is          "foo.bar.lol.pauldiz.co.uk:3000"
  assert uri.hostname is      "foo.bar.lol.pauldiz.co.uk"
  assert uri.href is          url
  assert uri.path is          "/a/b/c/index.html?q=arg&hello=world"
  assert uri.pathname is      "/a/b/c/index.html"
  assert uri.port is          "3000"
  assert uri.protocol is      "http:"
  assert uri.query is         "q=arg&hello=world"
  assert uri.search is        "?q=arg&hello=world"
  assert uri.canonical is     "uk.co.pauldiz.lol.bar.foo/a/b/c/index.html?q=arg&hello=world"  
  assert uri.domain is        "pauldiz"
  assert uri.publicSuffix is  "co.uk"
  assert uri.subdomain is     "foo.bar.lol"
 
I'm not as disciplined as I'd like to be but after cowboy coding for decades now, I've made enough major mistakes to see the light.

You absolutely must be testing code that deals with accounting. If you don't you'll end up in a world of hurt some day.