How to test?" is a question that cannot be answered in general. "When to test?" however, does have a general answer: as early and as often as possible.
Bjarne Stroustrup (1997). “The C++ Programming Language”, Addison-Wesley Professional