First of all, it is very important to simply learn some common integrations by rote (e.g trig functions, exponentials, polynomials, 1/x). If you know these well, it will often be easy to spot which technique to use when integrating a seemingly difficult function.
If you are in a situation where you have to integrate a function comprised of two different types of function, such as f(x)=xe^x, integration by parts can be useful (i.e substitute u for one part of the function and v' for the other, such that the you now have to integrate uv' with solution uv - integral(vu'dx)). It is often a good idea when choosing what to use as u and v to choose as u whatever simplifies the most when you differentiate. For example, in the above function I would make u=x and v'=e^x so that u'=1 and v=e^x. Then the integral of vu' is simply the integral of e^x which is quite simple.
Unless you are given case like this, integration by inspection (just by looking at it and using your known results) is always possible but can sometimes be hard to spot. If this is the case, it can be useful to use a clever substitution to help you. (Have a look at my solution to the integral of f(x)=x(1-x)^6 for an example of this