A pre-condition is something that
must be true when a method starts. This can be that a passed in parameter must have a certain range of values or that a class variable or instance member must have been initialized. Pre-conditions should never be checked using assertions in a non-private method.
Example:
public void aMethod(Object obj) {...}
Suppose that obj must not be null. If we verify that obj is not null using assertions then if assertions are not turned off we will lose the
test of obj. obj should be checked using standard if-else validation.
But suppose that aMethod was private. In that case we can use assertions. Why? Because if the assertion fails it is because of a bug in our code that we can correct once it is detected by the assertion during testing. SInce we corrected the problem during testing there is no reason to continue checking for null so in production we run with asssertions turned off and no checking is done.
Post-conditions are the conditions that must be true when the method completes. These are always appropriate to use with assertions since we are simply verifying that our code is giving the correct answer.
The key is that assertions should be used to check our own code during development, not that our code is being correctly used in production.