Yes, Dennis is correct! In the United States and California specifically you must test to promote to any rank, and "detective" or "investigator" is traditionally considered a "rank" in most agencies. Some smaller agencies sometimes use the rank of "Corporal" and have no "detective" rank. They use "detective" as an assignment. However, you still have to promote to the rank of Corporal. Of my 30+ years of Southern California law enforcement, 18 of those were at the rank of detective. Of those, I was assigned to homicide for 16 years.
To promote to detective, I had to take a written test, pass it and then take an oral exam. The oral exam was administered by both people from my department as well as other departments to eliminate undue influence. Preformance evaluations also were considered.
I fell in love with homicide and did not want to promote any further but the process would have been the same for each rank (Sergeant, Lieutenant, Captain, etc.)
Hope this helps.