I sympathize with dummies who don't write unit tests

Source: Internet
Author: User

J. Timothy King wrote a great article: Twelve benefits of writing unit tests first ). Unfortunately, what he said at the end of the article is completely superfluous.

However, if you don't want to get rid of the old habit of writing code first, if you think that self-stick is more important than designing good software, Well, I am sorry for you.

Using your pity on people who do not agree with you is not the most effective way to promote your claim.

Let's take a look at Mr t's example. He began to show mercy for dummies in the 1980 s, but so far, "Dummies" are still everywhere in the world.

Note: mr. T is an American actress. In his 1980 TV series"
The role B .a.baracus in A-team became famous. Later, he was still in the 1982 movie Rocky.
III as a boxer Clubber Lang. He always keeps the hairstyle of the iconic antman tinka warrior. In 2006, he made a TV show close to the real society. The program name is "I
Pity the fool "(I sympathize with dummies ).

J. Timothy King is a little self-defeating, because the ideas about unit testing are very important. The widespread acceptance of unit testing has become the past 5 ~ One of the greatest advances in the software development field in the past seven years!

How did you solve a software problem? Has the teacher taught you at school? What will you do first? When you begin to solve the problem, you will ask, "What code should I write to solve the problem ?" But this is actually a problem. The first question you want to ask is not "What code do I want to write", but "how can I confirm that my solution solves this problem ?"

There is a assumption in our education that we already know how to determine whether our solutions work. This is not a problem at all. For example, we can see the malicious behavior. We believe there is no need to think about what the code needs to do before writing the code. This kind of belief is deep-rooted and it is hard for most people to change!

J. Timothy King lists 12 specific methods to help you accept the concept of "test first" (This method has helped him write better code ):

  1. Unit Testing can prove that your code can actually solve the problem.
  2. You can obtain a regression testing tool for the underlying modules.
  3. You can continuously improve the design without disrupting existing functions.
  4. Writing Unit Tests and implementing code at the same time is more fun.
  5. They can be used to display the development progress in real time.
  6. Unit testing can be used as DEMO code
  7. It forces you to make plans before writing code.
  8. It reduces bug fixing costs
  9. Unit Tests are even better than code reviews
  10. It actually removes work barriers for programmers.
  11. Unit testing facilitates better design
  12. It is more efficient than writing code directly without writing unit tests.

In the above list, even if you only agree with 3 ~ 4-at least half of my experience is correct-it is also a huge improvement for software developers. I have no opinion on the importance of unit testing. On the contrary, I believe more and more that unit testing is so important that it should become the first class of language building (like classes, methods, events, etc ).

However, I think the advocates of "test first" (or "test-driven") are too focused on their own positions and a little eager for success. It is too much to require developers to completely change the way they develop software overnight. In particular, some developers have never written unit tests. For any software development organization, if they have not adopted unit tests as a standard method for each software project, I don't think they have the conditions to adopt the "test-driven" development method.

Excessive respect and worship of "test-driven" May cause software developers to doubt and dislike the entire concept of unit testing.

That's a pity! For software testing, testing is always better than unexpected. We are very familiar with the concept of ad-hoctesting. In fact, unit testing is a more formal random test, isn't it? I think Fowler has a very good saying:

Note: in software testing, in addition to testing according to test samples and instructions, random testing is also required, this module conducts spot checks on the functions and performance of the software based on the tester's experience.

Note: Martin Fowler is a world-class software development master and has made outstanding contributions in the fields of Object-Oriented Analysis and Design, UML, pattern, XP, and refactoring, he is now the chief scientist of thoughtworks, a famous software development consulting company. He has published many books, such as "Analysis Mode", "UML essence", "enterprise application architecture mode", and "refactoring: improving the design of existing code, has become a popular classic.

When you want to print some information to the screen or output it to the debugger, you should rewrite it into a unit test.

I hope developers can recognize the value of unit testing. I strongly advise them to develop the habit of writing structured test code while writing functional code. A little change in concept may eventually lead to a larger leap, such as test-driven development-but you must learn to crawl before you start running!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.