The key in Star Alliance is "operated by". For example, at one time SAA was not in *A. Lufthansa operated some flights from Europe to JNB, and code-shared others on SAA. As an Air Canada Aeroplan collector, I would get *A miles if I flew on an LH plane, and not if I flew on an SAA plane. This is kind of moot now that SAA joined *A, but the point still holds for other combinations.
Now, when you're looking at a site like Expedia that shows you a wide variety of flights, they will typically tell you who operates it. When you go to your own airline and ask for a multi-leg thing, for example asking Air Canada for YYZ-FRA-JNB, it can be hard to know who is actually operating the non-Air Canada leg. (Substitute your own airlines and cities as appropriate.) The answer is usually that it is the airline that uses a 3-digit flight number for it. If they tell you the leg is on LH8765 then it is probably not a LH plane; but LH876 probably is. (I say usually because for example Air Canada and United both have some 4-digit flight numbers that are operated by their LCC divisions - Jazz and United Express - but that are treated exactly the same as if they were operated by the mainline carrier.)
Now before you pull your hair out, remember that usually, it doesn't even matter because the operator and all the codeshares are all in the same alliance. It only becomes relevant if you happen to know that some of the codeshare partners on the route are not in the alliance.
To be sure, I will often do a "wide spectrum" search for the flight I'm considering, to let them show me the operating carrier so that I can then check my own plan to see what I will get. It's reasonably difficult to be confident - you have to understand all the fare classes on both your own airline and the operating airline. But you can learn this if you need to and want to.