locked
Cannot unit test CocosSharp objects RRS feed

  • Question

  • User360406 posted

    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?

    Tuesday, December 5, 2017 5:34 PM

Answers

  • User2051 posted

    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?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, December 11, 2017 12:47 PM

All replies

  • User360406 posted

    I just saw that this question is essentially the same.

    Wednesday, December 6, 2017 9:19 PM
  • User2051 posted

    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).

    Monday, December 11, 2017 12:00 PM
  • User360406 posted

    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?

    Monday, December 11, 2017 12:26 PM
  • User2051 posted

    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?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, December 11, 2017 12:47 PM
  • User360406 posted

    @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

    Monday, December 18, 2017 9:35 PM