Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question already has an answer here:

Should tests in some project be written by the actual person that does the coding (usually senior in our team) or it can be done by junior coders with less experience?

share|improve this question
3  
What type of tests? –  MichaelT Jul 31 '13 at 14:37
    
@MichaelT Unit testing, tests as part of the code –  deviDave Jul 31 '13 at 15:00
3  
Do "junior coders" don't do any "actual" coding in your team? What are they doing then? –  Paŭlo Ebermann Jul 31 '13 at 18:42
3  
I disagree this is a duplicate of the TDD question. That question is specifically about TDD, this one is more general. I think both questions have merit. The acid test, for me, is that I wouldn't move my own answer to the other question because it doesn't apply there. –  Bryan Oakley Jul 31 '13 at 21:51
1  
Unless I miss something, reopen justification doesn't make sense to me. 1. "That question is specifically about TDD, this one is..." surprise! it is explicitly and unambigously tagged tdd from the very beginning!. Those who believe this question isn't about TDD, didn't even bother to clean up that tag (along with appropriate explanation) - that's not how clearing the difference between dupes is expected to work... –  gnat Aug 1 '13 at 12:06
show 7 more comments

marked as duplicate by gnat, BЈовић, Dynamic, Michael Kohne, MichaelT Aug 5 '13 at 1:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

up vote 12 down vote accepted

There is no single answer to this question. Obviously, if you're a business with a single developer, then the developer should write the tests. If you're an organization of a thousand developers, the answer will be different.

Assuming a "normal" team with a few developers and possibly a few people dedicated to testing, it goes something like this:

  1. developers write unit tests
  2. developers and/or QA write integration tests
  3. QA writes acceptance tests

In the scrum model, there is no distinction between "developer" and "QA". The team as a whole is responsible for the quality of the software, and the team decides on a case-by-case basis who should be doing the testing.

Many smart people think developers should write all their tests. I've worked in organizations like that, and we always delivered exceptionally high quality software. In those companies, not only should senior devs write tests, they must.

Other very smart people believe that developers should not test their own code because they have blinders on. "I don't need to test X, my changes couldn't possibly have affected it". To combat that you should always have someone else write the tests. I've worked in those types of organizations, and there, too, we also delivered high quality code.

The bottom line is that if you're a developer, you are ultimately responsible for the quality of the code you produce. That means you should be writing tests -- regardless of organizational structure -- and if you have other team members, then you should work with them to make sure the code is properly tested.

In practical terms, the only people who can answer this for you is you and your team. It's perfectly reasonable for senior level programmers to write tests (and if they are good programmers, you won't ever have to as them to do it because that's just part of the job). It's also perfectly reasonable for junior people to write tests -- this is a good way for them to learn the software.

In either case, there is no should. You should do whatever allows your team to create software with an appropriate level of quality.

share|improve this answer
1  
I always advocated the idea that every developer should test code - just not their own. In any case, its never an excuse for some developers to pass off the boring testing work to some poor schmuck. –  gbjbaanb Aug 1 '13 at 12:00
add comment

Edit: I read the title as unit tests:

I have heard this idea before, and IMHO I think it is a terrible idea to force unit testing solely on junior developers.

You would be creating an unnecessary division in your team.

Developers should write unit tests for their own code. Both the code and unit tests will then in the future be updated by other developers as features changes and bugs are discovered depending on resource availability.

Not trusting juniors with real features is not the best way to manage projects. Start them on smaller or easier features, let them unit test them, and they can work their way up to bigger, harder features.

share|improve this answer
6  
I think it is an anti-pattern to have the concept of a 'junior developer'. Every team member has stronger and weaker areas, it's the job of the team leader to load balance the work. If the leader decrees that unit testing is something left to 'junior' then nobody will take testing seriously. That's a bad thing IMHO. –  Jim In Texas Jul 31 '13 at 18:06
    
@JimInTexas I agree! –  Ozz Jul 31 '13 at 19:40
add comment

Ideally, in test driven design, the test is written before a single line of code is written. Someone writes the failing test, someone writes the code (that passes).

In this model, it doesn't matter too much who writes the test (or who does the code). What is required is that the test accurately describes the functionality to be written before writing code. If this understanding of the requirements requires a senior programmer, then that is who writes it.

However, once the test is written, if it was well written, anyone should be able to write the code for it that passes the test. If anything, this points to that seniors should be writing the all tests and then delegating out the coding of the guts of the code to other people who can do it.

After the fact unit testing is.. less than ideal. Unfortunately, when this happens this is often left to the juniors to "get the required coverage." Such endeavors are often difficult because they are tedious and don't fully test the code in question (leaving bugs that get scapegoated on the person who wrote the test for not catching it).

It is great having junior programmers gain experience with the code base. Forcing them to write after the fact unit testing isn't the way to do it.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.