resharper-unity: Cannot run GameObject tests from ReSharper/Rider
When using anything inside the unity engine namespace when running unit tests in Resharper the exception “System.Security.SecurityException : ECall methods must be packaged into a system module” is thrown, for example:
using NUnit.Framework;
using UnityEngine;
[TestFixture]
public class ExampleTest
{
[Test]
public void UnityEngine_NewGameObject()
{
var newGameObject = new GameObject(); // Throws the exception
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 20 (9 by maintainers)
Rider 2018.1 will now run Unity tests in the Unity editor process, so it should fix the initial problem (ECall errors)
No. This isn’t a missing library, it’s Unity’s core API, large parts of which are written in native code, rather than .NET code. It’s not possible to mock this API without reimplementing all of UnityEngine.dll, which just isn’t feasible.
If a test makes use of any of Unity’s core (natively implemented) API, it has to run in the Unity Editor instance. There’s no way around this. But if the test is just plain .NET, you can run the tests in Rider.
The ideal solution, that we’re working towards, is that Rider will automatically run or debug in the Editor instance directly from the standard Rider testing UI.
Short answer is no, at least not yet. It requires the Unity editor plugin we’ve written for Rider, but we haven’t even investigated how much work it is to port that to ReSharper. The plugin makes a bunch of assumptions that it’s talking to Rider, not the least of which is the protocol used to communicate between Rider and the Unity editor. But we’ll take a look.
When I try running my tests I get this error from rider ‘Mono.Cecil.TypeDefinition.get_Interfaces’ not found."
I’m using:
Rider 2017.1 EAP Build #RS-171.4456.902, built on June 29, 2017 Rider EAP User Expiration date: July 29, 2017 JRE: 1.8.0_112-release-736-b17 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.12.5
Thoughts @citizenmatt ?
Correct, the assemblies have a dependency on the native application. Much of the API in the Unity assemblies are ICalls into our native engine, which needs to be initialized and running before calling them.
If you really want to have the tests running inside of Rider/Resharper/MonoDevelop, I imagine it would be possible for your test framework to invoke Unity’s Editor Test Runner via command line.