I want to use the term(s) when indicating a correct answer to a TEST question. I am thinking that one term may be preferred in TESTING situations, over the other.
As a Sino-Japanese compound, 正解 is more formal, and this is the word used in serious examinations and serious quiz shows. 当たり is more casual and colloquial, and it's mainly used for a riddle, a quick quiz, a "guess what" type question, or such.
当たり also refers to a completely random "win" or "hit" as in roulette or lootboxes. In this case, 当たり is not interchangeable with 正解.