views:

1472

answers:

17

Hello, I've moved from one team to another in same company. In old team (hardcore c++) we did lots of unit testing. In my new team (also c++) they do functional testing instead. During review they reject my code because of unit tests. Most of the team is interested in learning something new but not the guy who is VIP and has legacy developer approach. He has to accept code before commit. He resists the change. Advice?

// update: I'll inform in this topic what happened with my quest but please understand it's a big company, it takes time. Just to clarify, tests I do are fine and it always worked in other teams. I'm not new to this. From time to time I need to brake dependencies cause code it plain crap. In C++ you sometimes have to. That may introduce change in prod code just because of test. I believe having unit test justifies this kind of simple changes. It's better to have it than not.

// update2: Thanks for lots of good advice, clearly there is no silver bullet here :( Most of the team is convinced but 2 senior (15y+) devs are still opposing. I will give short talk on this the rest of my team will support me so I hope that those guys will just agree :) To relax a bit I've started learning ruby :)

+10  A: 

Store the unit tests in a parallel version control and only submit the code to the central system. He will review your code without unit tests and you still get to benefit from them ...

Additionnaly, I suggest using one of the distributed version control, you get to play with a new, fun toy, and when one of your other co-workers wants to try, he can easily embrace and extend your test suite.

Edit To clarify following comments:

I am suggesting he sets up a local source code repository for his unit tests. The code itself would still be synched with the managed repository (through the normal submission process just not submitting the tests along with the code).

He could also keep the unit tests he feels are useful on his hard drive and it wouldn't change anything, the same way any dev I know has a few "tool" files around for various purposes.

The idea is that working with unit tests, he can hope for his bug ratio to be lower than the others. It can help when arguing about this kind of thing with his tech lead. As long as he completes assigned work on time I don't see why he couldn't work as he sees fit.

Jean
That was the first question that leapt to mind for me: "What's stopping you from using unit tests and not telling anybody?"
JUST MY correct OPINION
It sound like you're suggesting that he set up a source code repository without management's knowledge or consent. Having an un-managed source code repository would be a no no in any audit.
uncle brad
I am suggesting he sets up a local source code repository for his unit tests. The code itself would still be synched with the managed repository. He could also keep the unit tests he feels are useful on his hard drive and it wouldn't change anything, the same way any dev I know has a few "tool" files around for various purposes. The idea is that working with unit tests, he can hope for his bug ratio to be lower than the others. It can help when arguing about this kind of thing.As long as he completes assigned work on time I don't see why he couldn't work as he sees fit.
Jean
I'll buy that for $1.00. If you edit your answer I can undo my down vote.
uncle brad
For my culture what do you mean by "I'll buy that for $1.00" ? that you are convinced ? (I am not a native english speaker but I love to learn new expressions :) )
Jean
Yes, I'm convinced. I wanted to say "I'll buy that", but it's too short for a valid comment. "I'll buy that for $1.00" is from the movie Robocop.
uncle brad
Thanks for explaining !
Jean
@Jean, @uncle brad - RoboCop is from 1987 so it is a bit old. :)
ChaosPandion
+6  A: 

In few minutes you should be getting some answers mostly favorable to you. Show this thread to that person who is resisting the code. :)

Bragboy
and buy him a cowboy hat. ;)
Eddy Pronk
+10  A: 

The most important thing in a development team is to stick to the standards, even if you dont agree with the standards. If everyone does their own thing, then there is no point in having standards.

You could keep the unit tests for your own personal satisfaction/confidence. Maybe one day you can demonstrate that your approach has stop a bug from reoccuring or benefitted the team in some way and then it may be easier to get your point accross.

One day you will be the guy setting the standards and then some people will disagree with you. Then you can tell them this story.

Disclaimer: I use unit tests when appropriate and anyone who works for me will be encouraged to as well.

James Westgate
While I agree with your general point, I can't give this a +1. Standards should not be upheld blindly without considering their impact. Otherwise, it's not a "standard", it's an arbitrary rule made without careful thought. In this case, enforcing a "no-unit-tests" policy could be seriously affecting the project in a negative way.
John Feminella
I dont think Im advocating upholding standards blindly. Im saying that sometimes theres a difference of opinion and fitting in with the team and the approach is more important. Maybe we shouldn't work together in future ;)
James Westgate
@James, @John - Lets stick with bloodletting because it is the standard. *Just trying to emphasis @John's point.*
ChaosPandion
@James: Having a difference of opinion is fine; competing viewpoints are how the best ideas make their way to the top. But you said "the most important thing" is to "stick to the standards". Standards are useful to have, but they should be cast aside immediately once it's clear that they're no longer serving the intended purpose, or if they actively become detrimental. If your team culture is such that standards are sacred and must be obeyed, it's really hard to raise alternative viewpoints when that kind of inertia exists.
John Feminella
So halfway through a project were all going to start coding and testing in our own way, Ill do something in F#, you can use prototype Ill stick with Jquery. Im not coming to the scrum meeting becuase I dont believe in Agile. No no no no .. no. no. noooo.
James Westgate
@James: Arbitrarily breaking standards is just as bad as arbitrarily making them. I think you're misunderstanding my point: Standards should be there because they provide a benefit appropriate to their cost. When the economics no longer make sense in light of the alternatives, it's time to reconsider. Standards should _not_ be there because "I say so", just like you shouldn't get to break standards because "C++ is stupid, let's use Ruby".
John Feminella
+1. You can continue to (politely) press for unit tests if you wish, but he's obviously the team lead. As long as the team performs, I'd say cohesion is way more important than methodology. Your use of language avoiding calling him the team lead is a little worrying. You're new to the group... find your place first, then try to suggest improvements. Immediately becoming subversive is a very bad idea. If the team sucks as it is, well then that's different.
darron
There's no telling from your description how you've implemented the tests. If I had a team member who wanted to do tests... I'd personally welcome it. However, they'd better be nicely organized off in a folder and not impact the main code line. Also, that team member would be expected to demonstrate the outcome was an overall improvement. For all I know, you've got #ifdefs all through turning on/off test versions of main(), etc. :) The phrase 'unit test' does not imply on it's own anything about how it's implemented. They could have had very good reason to reject it.
darron
+6  A: 

I'm sorry but you'll have to adapt yourself to the team. You'll have to speak them often about unit test, you can'nt convince them in one day.

My chief didn't know anything about oop and he was still programing in c#, now in convinced him to use constructor, maybe in a few month he'll do private field/ method instead of static method.

adapt yourself.

remi bourgarel
+1 for making me laugh. You have my sympathy for the boss...I see you are making progress with teaching him :D
Marek
+1  A: 

If the team is not experienced in maintaining a unit testsuite, then they have a problem, but you will hardly be able to solve it if he is more important in the company than you are.

Stefano Borini
+4  A: 

I'm a lazy bastard who doesn't write anywhere near enough unit tests, but I'm not idiotic enough to reject unit tests when my guys go to the effort of writing them. You could try to work within the confines of stupid management, but unless there's some hope that this guy is going to disappear from the scene soon, I suggest you find another team.

Marcelo Cantos
automatically assuming the rejection is stupid is a mistake. Who knows how the tests are implemented.Someone using a label you associate with a better design practice doesn't mean he's used it at all properly.
darron
It is entirely possible that the code was rejected for perfectly good reasons, but that's certainly not the impression I got from the OP.
Marcelo Cantos
Well the OP _would_ think it was not his fault, wouldn't he?
John
I was referring more to the claim that the other teammates seemed open to the ideas, while the lead was the only hold-out, which strongly suggests that the lead's rejection of the unit tests was ideological, not specific. Also, it is difficult to conceive of someone being told that their unit tests need improvement, and then coming on stackoverflow complaining that their lead is ideologicaly opposed to unit tests. Of course, anything anyone says could be an irrational lie, but I try to have a least some _a priori_ belief that people are honest, absent evidence to the contrary.
Marcelo Cantos
+42  A: 

You've just encountered the hardest software problem of all: people. While I'm hesitant to second-guess your boss without some more context (for example, is this really the complete testing picture?), an outright rejection of your code solely because you included unit tests is a questionable practice at best.

The most sensible route is have a one-to-one chat with this person so that you understand his position. You describe your boss as resistant to change, but usually people aren't so black and white. For instance, perhaps he views the volume of code you're submitting as risky given your new status on the project, not understanding that your unit testing enables you to write more code because you can have higher confidence in it. So I'd give him the benefit of the doubt, and have a heart-to-heart first.

Here are some questions to ask during your conversation:

  • What are your thoughts about unit tests? How do they fit into our overall testing strategy?

  • What are your issues with the unit tests I've been submitting? Are they deficient or lacking in some way? Are you okay with the unit testing itself, but would prefer that my code be organized differently?

  • Why should all of our code be tested at the functional level?

  • Are all unit tests bad or inappropriate for our project?

  • How do you plan to discover problems associated with specific inputs to methods when those conditions are more complex to replicate at higher interface levels?

  • If you have a specific objection to unit tests being checked in, is there any objection to using unit tests locally so that I can at least verify my own code?

If you feel that you now understand his position and it's untenable with the way you want to write software, you have a different question to ask yourself: Do you enjoy the work enough to stay on the team in spite of the professionally questionable practices, or is it time to start looking elsewhere?

Conversely, if you feel that you now understand why the rule is there and you think it's sensible in light of the overall context of the project, then huzzah! You avoided a potential crisis by handling yourself professionally, you get to stay with your new team, and you get to go back to the fun part: software development.


Edit: I really can't agree with some of the posts in this question telling the OP to adapt himself to the team. Standardization of practices is only good when the team buys into the practice. Instead of telling the OP to suck it up and fall in line, we should be encouraging him to understand why the rule is in place, so that he can evaluate whether it makes sense on its own merits.

The manager also has some explaining to do so that he can help the OP see things his way. Sure, not everybody will agree with managers all the time. I've led projects or teams, and made my share of decisions that couldn't please everybody, but I always tried to make them with input from everyone first, so that I could arrive at the best decision. In my opinion, enforcing a set of "standards" by managerial fiat without considering the impact to the team and ignoring alternative suggestions makes you a bad manager, not a good one.

John Feminella
Sensible route? I say we form an angry mob!
ChaosPandion
Don't try to understand him; just rope, throw and brand him. Soon you'll be livin' high and wide. (Rawhide!)
rtperson
Well, theres a time and place. Perhaps this is the middle of a project with a deadline?
James Westgate
@John - I must say it is refreshing to hear a view point that is absent of religious fervor. *whitespace vs tabs anyone?*
ChaosPandion
@James Westgate: Yes, I suspect there's at least some part of this that we're not hearing about. That's why I'm giving the manager a little bit of the benefit of the doubt; he's not able to present his side of the story here. (Although wouldn't it be cool if he saw this post and then responded on StackOverflow?)
John Feminella
@Chaos: Spaces! Tabs are for wussies. :)
John Feminella
I'd say it is more likely that they just aren't set up for tracking non-production code like his unit tests. There could be a million little technical reasons why it would be a problem.
T.E.D.
Standards are made to be followed... until you find a better one.
Pascal Thivent
@John - Tabs! Spaces are for people who can't configure their tools properly! ;)
zombat
+1  A: 

Rename your Unit Tests "en camera functional tests".

EDIT: More practically, if you cannot overcome the human element, you could maintain your unit tests in a small, private, parallel repository. Unpack them when you develop or maintain, run them, update them, then put them away until next time.

kmarsh
A: 

Interesting that the code was rejected because of unit tests. Had you left them out of the code you submitted for acceptance, would it have been accepted? If that is the case, you just keep doing unit tests and keep on churning out production code that passes those unit tests. If your tests are good ones, they'll only improve the production code you turn in. The "overhead" of writing the unit tests is not that much - certainly when compared to finding bugs downstream.

That said, you cannot walk into a new group and expect to change the culture of the group overnight - this just doesn't happen typically. Better that you keep up with your good practices and submit the code that passes your tests. In time, your coworker might come around or the rules might change. People are reluctant to change until they see the benefits.

If your code doesn't meet some other standard set by the group, you'll need to address that, of course.

itsmatt
+2  A: 

Have your team lead read this paper (pdf), (which you can find neatly digested in this blog post), and see if he changes his mind.

Now, one study doesn't prove anything, but there is one very intriguing take-away paragraph:

We found that test-first students on average wrote more tests and, in turn, students who wrote more tests tended to be more productive. We also observed that the minimum quality increased linearly with the number of programmer tests, independent of the development strategy employed.

In other words, better tests, better code. Period. (This squares with my experience, and the experience of countless other developers I've worked with.)

If you can't get this guy to change his mind, then look for work elsewhere -- you've ended up on one of those loser teams where those in charge are impervious to learning something new. Not good.

EDIT: there are dozens of studies showing the effectiveness of TDD. Try here and here for more.

rtperson
TDD is a subject get a bit over-zealous about though, talking about it as "The Way". I wouldn't call a team a "Loser Team" for not using them, especially considering they do employ other testing rather than no rigorous testing at all.
John
@John, I would designate a team as "loser" not because they're not using TDD, but because they're not at least somewhat open to new ways of doing things, even when research has shown those things to be helpful. The mindset of "Well, it's always been done this way" is crippling in a technical profession, as scores of COBOL programmers will tell you.
rtperson
+1  A: 

Keep writing those tests, but avoid writing trivial tests. Maybe with a trivial test you think you can educate others, but they might see it as proof of being a waste of time. Try to fix bugs by writing a test to reproduce the problem and do a presentation about what you did to the team. Try not to sell unit testing as the new religion, but try to explain why this is the way you work. Spend your energy on convincing the other team members first.

At some point they will notice you can make big changes to the implementation of your code without regressing.

Eddy Pronk
+1  A: 

One of the good advices I got during a university lecture on software quality:

If you get in a team/company where they really don't know how to make software. Try to help them improve (accept there isn't one good way, but not trying is not the way). Come up with good arguments (such as: my code has less bugs and takes the same amount of time to write?). If you can't change the company/team: Don't stay, start looking for a new job, with this company or another.

Thirler
Since when are university lecturers good at giving advice about real-world workplace situations?
John
Actually at good institutions some do. :)
Thirler
+1  A: 

It sounds to me like he is refusing to check in sources that contain code to perform unit tests, right?

The simple solution to that is to not try to check in your unit test code. You can still write it and perform unit tests, but keep it separate. If you want it revision controlled, keep your own separate repository for your unit tests.

This is how I've done it most of my 20ish year career. I think I've only ever worked on one program that officially tracked unit tests like your old group did.

T.E.D.
+8  A: 

Unit tests have costs, not just benefits. From http://www.joelonsoftware.com/items/2009/09/23.html:

Zawinski didn’t do many unit tests. They “sound great in principle. Given a leisurely development pace, that’s certainly the way to go. But when you’re looking at, ‘We’ve got to go from zero to done in six weeks,’ well, I can’t do that unless I cut something out. And what I’m going to cut out is the stuff that’s not absolutely critical. And unit tests are not critical. If there’s no unit test the customer isn’t going to complain about that.”

From: http://www.codinghorror.com/blog/2005/04/good-test-bad-test.html

My main problem at the moment with unit tests is when I change a design I get a stack of failing tests. This means I'm either going to write less tests or make fewer big design changes. Both of which are bad things.

Jon
I can't imagine you're going to get much love for this post! But I agree it's worth noting things aren't so black and white as TDD proponents like to believe.
John
It's worth noting that Zawinski hasn't worked as a professional developer since 2001. A lot has changed in the profession since he left -- notably the tooling around building unit tests in just about any language.
rtperson
On the other hand, the code base Zawinski talks about was so buggy that it destroyed the company (Netscape). The developers needed fast development to fleece the investors before they caught on.
Daniel Newby
@Daniel Newby - That's a little unfair. As I remember, Microsoft destroyed Netscape by unleashing the horror that is IE onto an unwary public and then insisting loudly that it was part of their operating system. That said, I had a look at Netscape's code when they open-sourced Navigator, and it was pretty ugly.
rtperson
@rtperson: It was Netscape that trumpeted the web-environment-as-OS idea - Microsoft was simply fulfilling customer requests. That the early IE versions, written in a panic, could thrash it only proves how bad the Netscape code was.
Daniel Newby
If I could refer to Joel again, a lot of Netscape's failure was because they decided to rewrite from scratch instead of refactoring. http://www.joelonsoftware.com/articles/fog0000000069.html
Jon
A: 

I'm going to propose a less dramatic version of John Feminella's answer.

Talk to the person in question but don't make a big song and dance about it. Certainly don't say "why don't you like me doing something which makes my code better", this is challenging his knowledge and given that many developers are quite sensitive about implied criticism, he may just tell you to get lost.

Instead I'd first clarify "did you only fail the review because i included this test code?" Then say "I find my productivity is higher when I write tests, what is the problem me checking in tests"

John
I like idea of "dancing" around the question, I'll try that!
Nazgob
A: 

On the flip-side, the reason unit tests may be rejected by the reviewer could be:

  • Likely, rules apply to all code in the project
  • This means unit tests means a lot more code to review
  • Unit tests may not be written in a way meeting general review/coding standards

Especially in C++, I imagine your tests kind of mix in with the main application code, since no unit testing setup exists in the project already. In which case it might make the code harder to follow.

John
A: 

This doesn't really address your question, but you didn't mention whether you're getting code coverage.

Functional testing plus code coverage can be effective in demonstrating code correctness and may have been popular when you manager was coming up through the ranks.

The main problem is that it's a lot of effort and not very practical when your code is still in flux.

uncle brad