Set- and Test- are run at completely different cycles, so there's not a reliable way to "share" information. And you definitely should not use global variables. What is it you're trying to do, more specifically?
I'm modifying Smbshare resource and I'm trying to test what user/permission should be removed from the share and assign it to global variable and pass it to set-TargetResource so then the user/permissions can be added or removed .
So I think the only option would be to implement validation in Set-TargetResoruce before making any changes .
The right design pattern is probably to have private functions that do all the "work." Those can then be called either by Test- or Set- as needed. Since there's obviously overlap in what Test- and Set- do, moving the functionality to separate functions lets you modularize your code, and maintain granularity.