Question by
bsteenwi · Mar 18, 2016 at 05:20 PM ·
editormonodeveloptestingmacosxmissingmethodexception
Unit test: PlayerPrefs, Attempted to access a missing method.
Hi,
I'm writing a unit test in the editor of monodeveloper. An object in this class uses an PlayerPrefs.HasKey call and works fine in game. However, the unit test gives an System.MissingMethodException when it tries to acces this HasKey method.
My code:
using UnityEngine;
using System.IO;
using System.Net;
using System;
using SimpleJSON;
using Network;
using System.Collections.Generic;
using EncryptString;
using System.Text;
/// <summary>
/// Session manager holds information about the current session and is responsable for getting it from the network manager.
/// </summary>
///
[Serializable]
public class SessionManager
{
INetworkManager network_manager;
private Session session;
private GUIStyle guiStyle;
public SessionManager(INetworkManager network_manager){
this.network_manager = network_manager;
}
/// <summary>
/// Method to request a login
/// </summary>
public void login (string username)
{
if (PlayerPrefs.HasKey ("Authorization")) {
....
My test:
using NUnit.Framework;
using Network;
using Network.IO;
using System.Net;
using UnityEngine;
using System;
[TestFixture()]
public class TestSessionManager
{
[Test()]
public void TestLogin ()
{
//delete all player prefs
//PlayerPrefs.DeleteAll ();
//initialize networkstub
NetworkStub stub = new NetworkStub ();
SessionManager manager = new SessionManager (stub);
manager.login ("john");
...
How can i solve this error? I'm getting the same specific error while doing this:
[Test()]
public void test(){
Debug.Log ("test");
}
System.MissingMethodException : Attempted to access a missing method.
Stack trace:
at (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,string,UnityEngine.Object)
at UnityEngine.DebugLogHandler.LogFormat (LogType logType, UnityEngine.Object context, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0
at UnityEngine.Logger.Log (LogType logType, System.Object message) [0x00000] in <filename unknown>:0
at UnityEngine.Debug.Log (System.Object message) [0x00000] in <filename unknown>:0
at TestSessionManager.test () [0x00006] in /Users/bramsteenwinckel/Documents/client/New-Horizon/Assets/Editor/Tests/Session/TestSessionManager.cs:46
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
Comment
Best Answer
Answer by Tomek-Paszek · Mar 29, 2016 at 02:25 PM
Try using Editor Tests Runner to run the tests (Windows/Editor Tests Runner)
Thanks, this solved it indeed! The standard unit tester in monodeveloper isn't able to unit test with unityengine components in my code. The Edit Tests Runner doesn't have any problems with this.
Thanks for helping me!