When a court sets a precedent, it is effectively creating a law (case law). This means that the law (or a newly clear interpretation that can only now be relied on) did not exist prior to the courts opinion being handed down.
If that is the case, it is trivially obvious that the person found guilty in such a "test case" could not possibly have broken the law, since the law is created at the moment of the decision.
Given that it is also clearly improper to hold someone responsible for laws that don't yet exist (violation of the "due process" clause), shouldn't those involved in test cases be protected from punishment? Are there any jurisdictions, or has there ever been a time, where "test case" defendants (and/or litigants in civil actions) are protected from punishment if a precedent is set from the decision? If not for the "due process reasons" but to encourage test cases that can improve the law—vs. the current approach which acts to prevent test cases because they are so risky. Has there ever been an attempt to implement such immunity, and if so, why/how was it defeated? Has a prosecutor and/or judge ever used their discretion to decrease or prevent punishment in a precedent-setting case?