views:

201

answers:

8

So here is the situation-- a quote from my boss: "[...] we need to focus on programming. [...] At the end of the day I want to write good software and not get bogged down with testing." This is said after we have had 3 months of a daunting list of bugs and recently designating a non-programmer to write web tests with Selenium framework.

My boss is very much unit-test shy (he can't see the cost benefit when it slows down developers). What are your opinions out there on web tests and programmatic tests in general? Should they be written by the (or a) programmer or does it matter? My thought was that part of writing good software is writing tests? He's a Microsoft ivory-tower kind of guy, and so any resources out there that have been put out by Microsoft (or good articles in general) in favor of testing by design would be helpful.

+8  A: 

Here's what I did.

  1. I wrote the tests anyway.

  2. I wrote the code after writing the tests.

  3. The code was rock-solid and (mostly) bug-free (to the limits of my abilities.)

I never told anyone I was doing TDD. Unless they ask.

It turns out that TDD is actually faster than messing around trying to design something, code it and hope it works.

A few things include an extra step 0: a "technology spike" to see how things work. This is followed by some test development to exercise the as-yet-not-written real software.

I'm a little behind schedule when it comes to starting design. Since my design is "design and write tests for that design" while some other folks design is "scratch around with some clever ideas but no real proof." Some folks can design on paper well. I can't. But I can design tests.

I'm generally pretty far ahead when it comes to finishing code. Since -- when I'm done coding -- all the tests pass.

S.Lott
I agree, and since there is probably no code review anyways no one will find out that you created unit tests.
Otávio Décio
+1 its called professional software development, and its how you professionally build it. If quality + speed isn't better than with the alternative, there would be a case, but its not. I'm adding an answer because unit and focused integration tests aren't all the types of tests in a project.
eglasius
While I agree this is a good process, there are a few reasons I'm not voting you up. 1) If you are a lone programmer this may be fine, but what happens on a team where multiple people have vastly different and contradictory approaches? TDD should be a team venture and they are missing out as a direct result of you being cagey about what you're doing. 2) This can throw off estimates if you aren't accurately documenting your process. 3) Read my answer for a discussion of ethics and responsibility of programmers to their managers.
M2tM
eglasius
I'd much rather a programmer set an example by being open and honest about their methods and take a stand and actually do the right thing by going ahead with their testing, but by being honest about it regardless of what management says than to simply nod and pretend to agree and then LIE about what they are doing. Sure, take your stand, do the right thing, build quality software. My point is that if you simply go ahead after being told not to do something and act as if you agree that is unethical! Take a stand, grow a pair, and stop hiding behind a lie.
M2tM
@M2tM that's overrating management involvement+opinion in it. The typical issue happens with how it was communicated to management, and usually sounds like "we need to do X, and it'll take more time / so we are either taking more time on the current tasks or we need to allocate extra times for these activities". Then in the conversation that follows, they don't know how to present the benefits in business terms and are not clear about it. That pointless conversation shouldn't have taken place. Now, I agree you don't go and hide ...
eglasius
... you say that you are a professional and that's part of how software is professionally built. That you can't do the wrong thing that will damage both the company and yourself, but you understand the concern about the schedules. You, as always have done, will take that into account and will make sure you don't negatively impact it. Additionally with all that said, that it would be best if the company was on board with these changes that will raise the productivity and quality of development.
eglasius
I think we agree for the most part, I think you misunderstand my point. All I'm saying is not to "write the tests anyway" and "not say anything unless people ask"... Those are really the two issues I have with this answer. If you have already had a conversation with your manager and they say "don't write tests" your answer should not be "ok" and then write the tests anyway. It should be "no, I cannot do my job effectively if you try to supersede my expertise on the subject. I am going to work on tests because it will streamline the process and we will see a quicker turn around overall."
M2tM
You should never say "yes" and mean "no". That is really what it comes down to.
M2tM
@M2tM: 'they say "don't write tests"' but "designating a non-programmer to write web tests". Means something. It means that management is saying one thing and doing the exact opposite. If you then try to say something like "I cannot do my job effectively if you try to supersede my expertise on the subject" you will do no good. Why not? Management is already behaving irrationally. Or perhaps worse -- insanely. A "conversation" won't help. Just take action. When management is sacked, and your code works, what will happen next?
S.Lott
Well, I'd already have a new, better, and more interesting job. I always assume I'm dealing with rational people when I approach pretty much anything. I recognize irrational people exist, but when I encounter them in life I either ignore them, attempt to extract them from my life, or leave. When they are literally holding my daily schedule in their hand and they are irrational I'm pretty sure ignoring the problem would be irresponsible so I'm either going to talk to somebody who can fire them or I'm going to leave myself. I don't think "taking action" via subterfuge is ever the right thing.
M2tM
A: 

I understand where your boss is coming from. After all, programmers should be able to churn out code that just "works". However, testing will happen no matter what, be it unit testing, integration testing in your company or after you install at the customer. Errors at each one of these stages have different costs and consequences, though...

Otávio Décio
They're finding that, because of the complexity of the system, there is a possibility (due to all the bugs) that customers will start leaving because of the number of them. Developers aren't finding the bugs, the customers are!
Josh Barker
As Sarah Palin says - you betcha!
Otávio Décio
+4  A: 

Code Complete is a book which is part of the Microsoft Collection. It contains advice advocating peer review and brushing upon unit testing as a concept. It does not go too far into detail with unit tests, but it may warm him up to the idea and you can further explore the topic from there.

Ultimately you need somebody who is a programmer directly involved in automating testing... I mean, that's by definition.

Unit tests are most effectively written by the people who are most familiar with the subsystems they are written for, when someone else is chosen to write unit tests it takes them time to ramp up, and they may miss intention not documented or clear in the code which could result in worse coverage. On the flip side, the owner of the subsystem can be blind to certain deficiencies as well (but this is what peer code reviews are for!)


The rest of this is really just idle discussion about ethics, but it's important to consider.

Some people like to try and "sneak shit in" to the build when management makes silly decisions. This makes me not only uneasy, but also kind of wary about those programmers. I understand the motivation, I think we've all been there, but ultimately you should educate rather than participate in subterfuge.

Management plays an important role in scheduling and they rely on you for both accurate estimates and a general understanding of work being done. If you pad your estimates to sweep extra work under the rug is that really a good thing? What was a simple lie becomes this elaborate hoax you're playing on the people directly involved in helping your career progress.

What was a problem with process and estimation for legitimate work has now become a sticky ethics issue.

I strongly recommend going about your planned approach of convincing your manager to see your point of view through reason, logic, and appealing to his love of Microsoft. ;)

Over the long term if you find yourself constantly fighting management on decisions about programming process (which really isn't their job to make decisions on) it would probably be best to polish up that resume and find a better job.

Part of a programmer's job is to educate the people involved who have less expertise. Explaining that to your manager may help break down some of the intellectual barriers he has on the subject and soften him up to accepting your advice on the matter.

M2tM
+1 because I made this comment when I read the question, then saw your answer. :D
drachenstern
I somewhat agree with the initials part of this, but I can't agree with the overall feeling of the answer at all. The bit that I agree the most is the one that somewhat says that automated testing requires developer skills (regardless of the title/role of the person in the project). @M2tM I just went over it on reply to your comment in S.Lott answer, but I strongly believe the opposite of what you mention on the later part to be the case - its unethical and its damaging the company/team to choose the slower + lower quality approach ...
eglasius
... There is no padding the estimates needed to be done for this, since its faster. In fact the same could be said of doing it without tests, you are padding the estimates with all that extra time you already know you'll spend without tests to help you out. Educating + convincing +getting others on board yes, negotiating something that's part of how You build software faster (and thus cheaper) and with higher quality, definitely no. -1 because all of the above.
eglasius
Actually, if you are lying about what you are doing and hiding your approach and performing non-standard methods which the rest of the team is not using regardless of the amount of time it takes that is unethical. PERIOD. If you have to be deceptive about your actions in order to effectively program you should probably get a new job at a better company. That's all I'm saying.
M2tM
Even if you are saving your company time and money, if you aren't open and honest about the methods you are using, and if you are knowingly staying quiet about it when the whole team should really be adopting the same strategy... I don't know what to say. Programming large systems is not a solo effort. It is a team activity and involves communication. I mean, really, do you want a team of hundreds of programmers to have a few little islands of test cases written with different ad-hoc frameworks? Probably not. That should be a team decision, if it isn't there is something SERIOUSLY wrong.
M2tM
If you're a solo programmer in some startup it may not be an issue beyond ethically questionable (lies are always ethically questionable), but for many companies which employ a large number of people it becomes a maintenance nightmare when everyone decides to sail off in their own direction.
M2tM
"performing non-standard methods" -> actually, that's what you get when all the team members go on with their own design views that completely disregard the old loosely coupled and high cohesion characteristics. " lying about what you are doing and hiding your approach" -> I answered on the comments in S.Lott answer that I agree that you don't go to hide, its more about being clear with something that's non negotiable.
eglasius
"I mean, really, do you want a team of hundreds of programmers to have a few little islands of test cases written with different ad-hoc frameworks?" -> that's actually a complete different issue and a different context. You don't just go on from top management and say to all the team managers: "starting next month All developers will do TDD/unit tests", that just doesn't work. And of course that you will initially have a few little islands of test cases and if the team is really large you will have different ad-hoc frameworks. In fact, enterprise architectures are no longer enforced that way
eglasius
"or many companies which employ a large number of people it becomes a maintenance nightmare when everyone decides to sail off in their own direction" -> like in my last comment, that's an old school view on how enterprise architectures happen in a company, and that just doesn't work. At the top level you shouldn't focus on one tool/framework to rule them all. Granted, we may have a different understanding on what's really a large company. As for medium sized companies, you still don't want to introduce something like this all around just like that, you want a couple pilot projects.
eglasius
A: 

You will often hear it's a good idea to make other people test your code because they might interpret the spec differently. However, the benefit of writing the tests for your own code is that you know where it can be defective.

An efficient approach could be a mixture of both: the programmer writing his own unit tests, focusing on corner cases and someone else doing some functional testing, focusing on the higher-level specification.

gawi
+1  A: 

I go for the world that for something to be "done done " it needs to have been verified by at least two people. You don't always need a software tester on the team if everyone on the team believes that quality of software is everyone's job.

If you want it to be highly efficient then the developer writing the code should be writing the tests and someone reviews them with the production code. If you want to be highly effective then pair with someone and they write the tests while you write the code in a "paired tdd".

Remind the manager that the cost of bugs grows expontentially the later it is found.

AutomatedTester
A: 

Not all tests are created equal, lets go over some:

  • Unit tests / TDD. Its hard to argue against it, specially as its the opposite to "he can't see the cost benefit when it slows down developers", its faster. S. Lott goes over the details.
  • Focused integration tests. Same as above, its faster. No having to run through a series of steps through your fully integrated app, to find out if that very thin layer of integration code you just wrote is working. That's worst when you consider that's repeated as many times you have to go in there, and even more when it wrongly becomes tightly coupled to different processes.
  • Full system tests. With the above in place, you just want to know if all the pieces were hooked correctly and if the UI is working as expected. For the earlier you need a tiny bit amount of tests that are very quickly written; compare that to how many times people go manually over it (including yourself) and you have a winner :). For the later there are some things that are hard to catch with automated tests, so you don't focus automation on those.
  • Exploratory tests. These should still be done, hopefully enough thought is put before the feature is built to avoid having to do extra changes at this point.

Now, QA usually comes up with additional scenarios. This is good, but its best when its included in a collaborative way in the automated tests.

One real issue can be current team skills. Unit testing is harder the more coupled the code is, this is usually worst with existing code with no unit tests, but it also initially makes it harder to move forward for a developer that doesn't know well how to design code loosely coupled/high cohesion code. It needs to be done, but be aware of this as the cost will go somewhere (to the team members or the company).

eglasius
"its faster"- I would tend to agree with you, except its not exactly faster if you have a team of 4, and 3 out of the 4 have never written a test in their life. I think it takes time to get the hang of TDD when you've never been introduced to it.
Josh Barker
@Josh that's why I added that part at the end. Its a training issue, and there is a cost associated if that's the case. That cost will go somewhere, and given the situation you can't just move that cost to the company. If you feel strong about this for your professional career you will have to own that cost / just like when you learn a different platform on your own time. Alternatively there is the change work option to a company where you can learn from the team, given you find one that's willing to add a team member that have no experience in TDD and its related aspects.
eglasius
A: 

To create a good test suite, it takes quite a bit of effort; this will take longer than expected.

In this respect, your boss is right.

However, if you plan to extend your product (add features) or web site (add pages and javascript code), then you need to do create the suite anyway at a later time, though.

knb
A: 

You could point out that unit testing has be built into the .Net framework since VS2005.

Nat