How to discover bugs as early as possible to improve software qualityArticle. When we see the asserted technology, we feel that the asserted is everyProgramEssential basic skills. The bug in the program can be asserted to be found in the place closest to the place where it occurred to prevent the spread of the bug.
The use of assertions in. NET is using system. Dig. debug. Assertions generally take effect when the program is in debug mode. When the program is released (that is, the release mode), the compiler uses Conditional compilation to remove the assertions from the release DLL.
Use assertions in several scenarios, such:
1. Validity of method parameters
2. Assert the illegal situation and make continuous statements about the error situation and must handle it
3. assert any assumptions
4. Check the assumptions of the Program Development Environment (OS/Compiler/hardware) with assertions.
5. Write an error prevention program, and then use an asserted statement to declare an error after processing the error (usually the default statement in the switch statement is asserted)
6. Use assertions to ensure that unspecified features or functions are not used (if some of the previously defined functions have not yet been implemented, assertions should be made ).
I agree with the use cases of these assertions. However, I have the following questions:
1. For the first entry, since the assertions will be automatically removed from the program's release version by the compiler, we often develop a basic library, how can the public and protected modifier ensure the legitimacy of the parameters entered by the caller? (of course, if the caller is using a debug program, there is no problem ).
2. We release the program to users. Even if we use assertions during the development process, the quality of the program can be greatly improved, but there are still bugs in the program. So how can we find a bug in a release-version program that is the closest to the place where the bug is located, just like in the debugging phase? Currently, I only think that I can capture all exceptions at the top of the program and save the exception information and stack information as logs. However, at this time, it is difficult for us to locate this bug because it is hard to locate its place of birth.