There are testing services out there, as well as fentanyl test strips you can use to determine presence of fentanyl in drugs.
To answer the question, gram per gram fentanyl is more expensive than heroin, partially because it's a synthetic chemical that requires several steps to manufacture and a process much more complicated than converting opium from poppies into heroin.
The reason it is touted as a "cheaper alternative" is that a dose of fentanyl is about 1/50th of a dose of heroin, by weight. A typical dose of heroin might be 25 milligrams, but the equivalent dose of fentanyl is 500 micrograms or 0.5 mg. This means unscrupulous dealers can make large amounts of fake "heroin" from small amounts of fentanyl.
The problems with fentanyl are: it's more toxic than morphine or heroin, that is, easier to OD on. 2 milligrams (0.002 grams) is the average lethal dose of fentanyl for someone who has no tolerance to opioids. A lethal dose of heroin in the same individual could be up to 500mg. Another is that fentanyl has a much shorter duration of action than heroin - so you have to do it much more frequently. And another is that many people find it less euphoric or satisfying than heroin.