Unit testing and motivation for it
I am currently testing an application that does not support unit testing support, a lot of dependencies, refactoring and the developers who build the application didn't think about unit testing when they started developing. My task is to conduct research for unit testing, unit test the application and bring unit testing to the organization.
When I'm working on an application and writing unit tests, it can sometimes be quite difficult to maintain good motivation and write good tests for complex pieces of code.
Now my related questions are:
1. How can you motivate you to write good unit tests? (for legacy code)
2. Is it important to motivate your colleagues to write unit tests?
3. As an employer, how can you motivate your employees to write good unit tests?
a source to share
While I agree with other posts, I want to add that, in my experience, creating unit tests for legacy code is one of the best ways to start refactoring evil. Of course, this may sound cumbersome, but it will help improve your knowledge of the code base, its strengths and weaknesses, and give you the opportunity to improve the quality of progress.
a source to share
People get motivated because of the ADVANTAGES. People don't want to do what they think is MORE work. Unit Testing means LESS. This means going out with girls more. This means you get more because you don't have to code until 11pm every night. This means that you are going to rest more. This means that it is faster to produce software for people who are not interested in pawning.
I found that when I started doing TDD (back in 2002 or 2003) it was a little odd ... but even within a few days I started to feel huge performance benefits.
The biggest advantage of TDD is that you can refactor your program to a better design ... or just change the name of something ... and as long as that design doesn't break the tests, you can get 100% certainty that your change nothing broke.
Obviously the importance of this increases the more your project is. With massive projects, this is an absolute godsend in terms of time savings.
Another big advantage is that if you have to create a bug on your system, you know right away. There is no expense tracking it. Who likes to track bugs? I do not. Your colleagues don't either.
The goal of TDD is to write a test, write code, and run tests. If you notice a whole bunch of tests going on when you add some new code, you'll immediately know what caused it. There really isn't a need for a debugger or posting print instructions throughout your program to find out what's wrong. So much time has been saved!
Another big advantage is that you can start with the design you want - at a high level, and not worry about implementation until you start coding. You can work with finer-grained details as you go. This means that the design of your classes should be more correct than doing things from bottom-up design. This means you don't have to reorganize it to get the design you want because you couldn't see the forest through the trees.
Another amazing benefit is that you have more confidence in your overall code. You KNOW it works. This has been proven. While this doesn't prove that you won't have any bugs, it does prove that all the expected problems you could think of have been taken care of.
As you gain experience, you will use more and more ways to hack your system. Every time you come up with one, you write a test to break it, and then you write code to fix it. By doing this for everything your mind is capable of, your system should be pretty solid. Basically, it is a piece of mind that cannot be given by just blind coding.
This means you can get pledged items and you don't have to worry about a phone call asking you to get back to work to fix a critical error.
Anyway, this is my commercial pitch for TDD. BENEFITS!
a source to share
As an employer, how can you motivate your employees to write good unit tests?
-
Do you have performance metrics that measure the quality of unit test and unit test coverage as decided by some robust process (peer review?)
-
Be very clear about the benefits of good unit testing (e.g. improved maintenance costs, fewer bugs, easy / safe refactoring / re-execution).
-
Have a testing culture. No code releases / reviews without new / changed functionality. Essential reviews, including test reviews. Test cases are part of the requirements / specifications.
Is it important to motivate your colleagues to write unit testing?
- Yes. Unit testing is not very easy, especially good, fair unit testing. And the benefits are not instant compared to the costs. Therefore, people tend to miss him if they are not forced by politics, very convincingly convinced examples, or brainwashed culture. Ideally all 3.
a source to share