Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make junior programmers write tests? [closed]

We have a junior programmer that simply doesn't write enough tests.
I have to nag him every two hours, "have you written tests?"
We've tried:

  • Showing that the design becomes simpler
  • Showing it prevents defects
  • Making it an ego thing saying only bad programmers don't
  • This weekend 2 team members had to come to work because his code had a NULL reference and he didn't test it

My work requires top quality stable code, and usually everyone 'gets it' and there's no need to push tests through. We know we can make him write tests, but we all know the useful tests are those written when you're into it.

Do you know of more motivations?

like image 783
abyx Avatar asked Aug 10 '08 17:08

abyx


People also ask

Should you write tests before code?

It often makes sense to write the test first and then write as much code as needed to allow the test to pass. Doing this moves towards a practice known as Test-Driven Development (TDD). Bluefruit uses a lot of TDD because it helps us to build the right product without waste and redundancies.

Do programmers write tests?

The Concept of Developer-Based TestingIn some teams, developers are expected to conduct unit testing at a minimum. They are asked to produce automated, integrated, and code-based tests. Building tests take time and instead of doing so, most developers prefer to use that time to create new code and features.

Why can't developers test their codes?

This is because someone testing something they created may bring unconscious or unintentional bias into the testing process. Software developers lack the objectivity to be able to test their own work.


1 Answers

This is one of the hardest things to do. Getting your people to get it.

Sometimes one of the best ways to help junior level programmers 'get it' and learn the right techniques from the seniors is to do a bit of pair programming.

Try this: on an upcoming project, pair the junior guy up with yourself or another senior programmer. They should work together, taking turns "driving" (being the one typing at they keyboard) and "coaching" (looking over the shoulder of the driver and pointing out suggestions, mistakes, etc as they go). It may seem like a waste of resources, but you will find:

  1. That these guys together can produce code plenty fast and of higher quality.
  2. If your junior guy learns enough to "get it" with a senior guy directing him along the right path (eg. "Ok, now before we continue, lets write at test for this function.") It will be well worth the resources you commit to it.

Maybe also have someone in your group give the Unit Testing 101 presentation by Kate Rhodes, I think its a great way to get people excited about testing, if delivered well.

Another thing you can do is have your Jr. Devs practice the Bowling Game Kata which will help them learn Test Driven Development. It is in java, but could easily be adapted to any language.

like image 118
Justin Standard Avatar answered Oct 21 '22 10:10

Justin Standard