mapbox / mapbox-sdk-cs

C# libraries for Mapbox API layer
https://mapbox.github.io/mapbox-sdk-cs/
Other
20 stars 11 forks source link

add mock UnityEngine unit tests. #41

Closed isiyu closed 7 years ago

isiyu commented 7 years ago

we're using UnityEngine in a few places - which makes it difficult to test, since it's not extensive we should be able to mock it pretty easily

https://github.com/mapbox/mapbox-sdk-unity-core/search?utf8=%E2%9C%93&q=using+unityengine

isiyu commented 7 years ago

@BergWerkGIS - I was thinking about just mocking the data structs that we need from UnityEngine like the aws mock module we use for testing mapbox-core tools. Seems like this would be possible with c#?

https://www.npmjs.com/package/aws-sdk-mock

wilhelmberg commented 7 years ago

Sure, mocking is possible with .Net/C#.

There are almost endless options:

http://nugetmusthaves.com/Tag/mocking http://codetuple.com/articles/unit-testing/rG8NM9372kj/mocking-frameworks-a-comparison-aspnet-1 http://www.coderewind.com/2014/07/top-5-mocking-frameworks-net-developers/

I haven't needed any mocking yet, so not able to recommend any. @david-rhodes ideas?

I recently read about NSubstitute being quite good. Github repo also seems to uptodate. https://github.com/nsubstitute/NSubstitute https://nsubstitute.github.io/

david-rhodes commented 7 years ago

I used NSubstitute exclusively at my last job. Unity also packages a special version of it with their test tools suite. I strongly recommend it.

That said, I'm not sure how you can "mock" anything in this case (UnityEngine). Given that Vector2 is a struct, for example, there's nothing to be done with regards to testing that would allow it to be used in Unity as well, without converting one struct to another.

Generally, mocking in C# is done via interfaces. You would only be able to mock by substituting for an interface (rather than a concrete class). A struct has no interface backing it. Of course, you could use a fake object in this case, but as mentioned before, you would need to convert a Mapbox.Vector2 to a UnityEngine.Vector2 to use it in Unity. I'm not sure the cost or time is worth it.

Great reading here: https://martinfowler.com/articles/mocksArentStubs.html (especially about dummy vs fake vs mock vs stub).

wilhelmberg commented 7 years ago

Not necessary anymore. Background: https://github.com/mapbox/mapbox-sdk-unity-core/issues/42#issuecomment-277959483