For groups $G$ and $G'$, if $f: G \to G'$ is a homomorphism, we have for all $x,y \in G$, $f(xy) = f(x)f(y)$. It is easily provable that it is necessary that $f$ carries identity to identity and inverses to inverses.
My question is: are either of these conditions sufficient for $f$ to be a homomorphism? Both follow from the statement that $f(xy) = f(x) f(y)$, but does $f(xy) = f(x)f(y)$ follow from either? Or are there cases where, for example, $f(1_G) = 1_{G'}$ but $f$ is not a homomorphism?
I haven't been able to find a convincing answer to this elsewhere.