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?
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).