When can we use derivative test to identify injective function? I have doubt regarding first derivative test for identifying whether a function is injective or not:
For example:
$$f(x)=\ln x$$ has domain $(0, \infty)$.
Now 
$$f'(x)=\frac{1}{x} \gt 0$$ hence $f(x)=\ln x$ is strictly increasing and hence injective.
But if we consider:
$$f(x)=\tan x$$
$$f'(x)=\sec^2 x \gt 0$$
But still $\tan x$ is not injective.
So can I know the formal conditions to test whether a function is injective or not?
 A: First, I think this is a good question, one that I wish more students considered.  The function
$$
f(x) = \begin{cases}x+5, & x < 0\\ x, & x > 0 \end{cases}
$$
has a derivative which is always positive ($1$, in fact) when it exists. However, it is clearly not injective.  The problem is that the domain is disconnected, coming in two separated pieces as $(-\infty, 0)$ versus $(0, +\infty)$.
The symptom: the fact you wish to use is really the MVT in disguise, but that demands an interval as part of the hypothesis.  And, sure, enough, $f$ is injective when restricted to any connected segment in its domain.  The same thing happens with your $\tan x$ example. 
Finally, the answer to your question: it is safe to do this when the derivative is strictly positive (or negative) across an interval.  Also, having a zero in the derivative isn't necessarily bad, but you have to be careful (e.g., $f(x)=x^3$, which is still injective). 
A: When you gave the $\log{}$ example, you specified the domain over which you're interested, but not in the case of the $\tan{}.$ Why not? The domain  of definition of a function is very important and should be specified always, not least in this situation -- i.e., when you want to conclude from the constant sign of the derivative to injectivity. It all depends on the domain.
I shall assume the domain of $\tan{}$ is the maximal possible one, since you do not specify it. Now, this domain is different from the one for the $\log{}$ in that it is not an interval, but a union of intervals. This is why the conclusion does not follow, and the test failed. If a function has a derivative with constant sign over an interval, then it is strictly monotone over that interval, and hence injective there. This is what can be safely used. It makes a statement valid over intervals, but is silent about unions of intervals, for example.
