Cannot unit test CocosSharp objects

MatExMatEx NLMember ✭✭

I want to use CocosSharp objects in my unit tests, but it always throws me vague NotImplementedExceptions. If I run this test:
[TestMethod]
public void MyTestCase()
{
CCPoint myPoint = new CCPoint(3, 4);
}

it throws a NotImplementedException that originates from the constructor of CCPoint, and the stack trace shows only that. Now, if I change it to
CCPoint myPoint = new CCPoint() { X = 3, Y = 4 };
it works. But I can't rely on tricks like this all the time. Also, if I run the code that I test from an Android project, no exceptions are thrown, it works there just fine! What it this thing then? Do you know?

Best Answer

Answers

  • MatExMatEx NLMember ✭✭

    I just saw that this question is essentially the same.

  • DomiBDomiB BEBeta, University ✭✭

    It's the way PCL projects used to work. A PCL project is basically a shim of underlying platform specific implementations, so if your tests are link against that code, it is code that does basically nothing (e.g. throwing NotImplementedException in constructors).

  • MatExMatEx NLMember ✭✭

    I just saw that this question is essentially the same.> @DomiB said:

    It's the way PCL projects used to work. A PCL project is basically a shim of underlying platform specific implementations, so if your tests are link against that code, it is code that does basically nothing (e.g. throwing NotImplementedException in constructors).

    All right, but then is there really no way to use that code in unit testing?

  • MatExMatEx NLMember ✭✭
    edited December 2017

    @DomiB said:
    I haven't tried this, so don't ask me how, but linking to the platform specific implementation instead of to the PCL should in theory do the trick?

    Indeed, you were absolutely right. By linking to the Android version of it, it works perfectly well. I haven't tried the iOS one, but I guess it should work also, based on the same principle. Thanks man

Sign In or Register to comment.