DenkzeitWiki

Suchen:

Aktuelle Änderungen Printable View Änderungen Bearbeiten

Agility > AgileSoftwareEngineering > Aikido > Ajax > AlanTuring > AlexanderStepanov > AlfonsKemper > AllRecentChanges > AlternativeDBSystems > Amazon > AndyHunt > AntiVirusSoftware > Apache > ApplicationServer > ArchitectureAstronauts > AsWeMayThink > AssertionsClear Trail
Main /

Assertions

DesignByContract
DifferenceExceptionsAndAssertions

UnitTests
DefensiveProgramming

The 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.



  1. Detect subtle errors that might otherwise go undetected
  2. . Detect errors sooner after they occur than they might otherwise be detected
  3. Make a statement about the effects of the code that is guaranteed to be true
The benefits of #1 are obvious. The benefit of #2 is not in finding a bug that's going to be found anyway, but rather in making it possible to find the bug faster. This can have significant effect on the bottom line, since programmers are not cheap. The benefit of #3 is harder to quantify, but there is not doubt that seeing a function assert that one of its parameters is not null tells a programmer more than a simple comment that the parameter should not be null, and much, much more than totally undocumented code.

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]


Assert

auch: DesignByContract

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]


Edit - BackLinks - Tags - Page Hist - Print - Changes - Home - Orphans - Help

Zuletzt geändert am 27.07.2005 13:38 Uhr und seit 7. April 2005 1097 aufgerufen.