My problem is that when I publish my project it includes that “Resources” folder incorrectly and because the script attached to the ScriptableObject doesn’t exists, it triggers that error in the console.
You want to use real Resources API (in order to run player tests in a real build) so you need to call it “Resources” but you get the problem that it will get included in a real player build and it should not as it’s inside the tests folder. There should be at least an API to filter resources that gets included in the final build because it’s not the same to do a build to execute runtime tests or to build a real project that includes a Packages with this tests.
You want to only run tests on editor so in that case you can call the folder as you want and load it with C# File API.
If you want to dynamically load a resource during an Editor test, use AssetDatabase.LoadAssetAtPath(). That will let you load an asset from any path, without needing any special folder names.
For playmode tests - we don’t have a great automatic solution today. I would probably try and build the resources into an AssetBundle that you can include/exclude from the StreamingAssets folder.
You might be able to use the ITestPlayerBuildModifier attribute to solve this. You can customise which scenes are included, so you could add a scene which contains a MonoBehaviour that references your test resources.
But if I specifically want to use Resources API because I want to test a method that uses an asset loaded from Resources folder… Your approach it’s entirely different.
In that case what I’d do is have the resources in a Resources folder, and use an IPreprocessBuildWithReport to move/rename the folder prior to making a normal build, then IPostprocessBuildWithReport to move it back again.
But really, this kind of thing is why we recommend against using the Resources folder.