Let $f(x)$ be a function defined by $$f(x)= \int_{1}^{x} t (t^2 -3t +2) dt $$ $1\leq x \leq 4$.
If we try to find the maximum of $f(x)$, I would differentiate $f(x)$ and find the critical points. By The Fundamental Theorem of Calculus, $$ f’(x)= x(x^2 -3x+2) $$ Critical points are (keeping in mind that $x \in [1,4]$) $1$ and $2$.
$f(1)=0$, $x=2$ must be the point of maximum, but by actual calculation it is found that $f(4) \gt f(2)$. Why the derivative test failed here? (Or did I use it in an improper way?)
Setting the first derivative to $0$ only tells you what the critical points of the function are. To determine the nature of the critical point, you usually have to look at the second derivative.
Even after this, you should always keep in mind that these derivative tests only tell you local information; a-priori you can only tell whether a point is a local maximum/local minimum (or a saddle point). This is a very important thing to realize because it is possible for a function $\phi$ to have two critical points $a<b$ such that $a$ is a local maximum, $b$ is a local minimum , but yet $\phi(a)< \phi(b)$ (this is why the adjective "local" is used).
If you want to identify any global maxima/minima, you also have to look at the boundary of the domain of definition to see how the function behaves there, and compare all the points respectively.
Above are just your conceptual mistakes. Some other mistakes are: why do you say $x=2$ is a point of maximum? Go over your reasoning carefully (it is actually a local minimum).