Aktuelle Änderungen Printable View Änderungen Bearbeiten
Agility > AgileSoftwareEngineering > Aikido > Ajax > AlanTuring > AlexanderStepanov > AlfonsKemper > AllRecentChanges > AlternativeDBSystems > Amazon > AndyHunt > AntiVirusSoftware > Apache > ApplicationServer > ArchitectureAstronauts > AsWeMayThink > AssertionsClear TrailThe role of assertions is to identify bugs in a program. Ideally, thorough testing of a program will find the bugs in a program even without the aid of assertions. In practice, the major benefit of assertions is to make testing more effective. This is an important point. An assertion that is never executed tells you nothing. An assertion is only useful if the code path containing it is executed.
I must say I do like assertions a lot. They aren't, and don't want to be, a universal way to check all of your preconditions, postconditions and invariants all the time. They are a straightforward way to embed those checks that are worthwhile to have as testing and documentation, but either too strict or too expensive to perform in production. [1]
Can't we view assertions as merely an early attempt to have UnitTests that are embedded in the code? Assertions provide a simple way to insert a stub test for the calling function(s).[2]
An assertion is a statement in the JavaTM programming language that enables you to test your assumptions about your program. For example, if you write a method that calculates the speed of a particle, you might assert that the calculated speed is less than the speed of light.[3]