ArticleDirectory
1. Build a Test System
If you want to refactor, you must first have a reliable test environment.
"Write Excellent testsProgram, Can greatly improve my programming speed, even if it is not reconstructed ."
1.1 self-testing Code (Self-testing code) Value
"Class should contain their own test code ."
"Each class has a test function and uses it to test its own class ."
Make sure that all tests are fully automated so that they can check their own test results.
Add the test immediately as long as you have written some functions.
A group of a suite of tests is a powerful "Bug" detector that greatly reduces the time needed to find "Bugs.
"In fact, the most useful time to write test code is before you start programming. When you need to add features, write the corresponding test code first. It sounds like we are not. Enter the test code and ask yourself: what is required to add this function. Writing Test code also enables you to focus on interfaces rather than implementing them (which is always a good thing ). The pre-written test code also marks the end of your work as a clear sign: Once the test code runs normally, the work will end ."
Build self-testing code.
1.2 JUnit testing framework (testing framew)
Frequently run the test. Take the test into account every compilation and execute each test at least once a day.
Unit Test and function test
"Whenever you receive a bug report, write a unit test to expose the bug ." -- How to expose it? Here, we need to accurately locate the problem based on the report. Will unit testing be helpful?
1.3 add more tests
"Observe what the class should do, and then test any possible failure of any function ."
"Testing should be a risk-driven behavior, with the purpose of identifying possible errors, either today or in the future ."
"The trick is to test what you are most worried about ."
This is not the same as my current thoughts. My current idea is that testing requires 100% guarantees for the program, so we need to test every possible situation of the program's behavior to ensure its correctness. According to my idea, the value field settings and access functions should also be tested. The author means that testing Code requires the lowest cost to get the greatest benefit. This requires me to make a choice in the actual environment.
"Writing is not a perfect test and running, so it is better to wait for the perfect test ." -- I am skeptical.
Use the functions before and after the test case: teardown and setup to ensure that the test cases are isolated from each other, rather than affecting each other.
Be a lazy programmer --.
Consider possible Error Boundary Conditions and set the test firepower there.
"Testing (priority) can increase programming speed", I need to verify in practice, if so, then I will try to implement this method in our department.
"When the test reaches a certain level, the test benefits will decrease ." Therefore, you should not expect to identify all the bugs Through testing, but to identify the vast majority of bugs through testing.
This is actually in line with the "20% Law": 80% of tests can find 80% bugs, and the remaining 20% tests can find the remaining bugs. All we need to do is write the 20% tests instead of the 100% tests.