khoi
khoi2mo ago

UnityTest Framework with Normcore

Any way to run tests on Normcore RealtimeComponents? For example, I want to call "CheckTwoHandsInSetsFooTrue" and then the test can be model.hands.Insert("x"; model.hands.Insert("y"); assert this.foo = true; Would it have to be a PlayMode test?
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @khoi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- There is no explicit documentation in the provided knowledge sources about using the Unity Test Framework (UTF) specifically with Normcore RealtimeComponents. However, based on how Normcore works, there are some important considerations: - Normcore RealtimeComponents depend on a live connection to a room and a running Realtime datastore. This means that most of their functionality (such as model synchronization and event firing) only works when the component is connected to a room, which typically happens during Play Mode in Unity. - Editor (EditMode) tests in Unity run outside of Play Mode and do not execute MonoBehaviour lifecycle methods or allow for scene-based networking. Therefore, you would not be able to fully test RealtimeComponent behavior (such as model synchronization or event-driven updates) in EditMode tests. - PlayMode tests run in a simulated Play Mode environment, allowing MonoBehaviour lifecycle methods and scene-based networking to function. This is the appropriate context for testing Normcore RealtimeComponents, as it allows the Realtime system to initialize, connect, and synchronize models as it would in a real application. So, to test something like your CheckTwoHandsInSetsFooTrue method, you would need to write a PlayMode test. In this test, you would: 1. Set up a scene with a Realtime component and your RealtimeComponent under test. 2. Connect to a room (using a test app key). 3. Manipulate the model (e.g., model.hands.Insert("x"), etc.). 4. Assert the expected state (e.g., Assert.IsTrue(model.foo)). Summary:
Yes, you would need to use a PlayMode test to properly test Normcore RealtimeComponents, as their functionality depends on the runtime environment provided by Play Mode. The knowledge sources do not provide a direct example of this, but this approach is consistent with how Normcore initializes and synchronizes components in Unity scenes and prefabs Synchronizing Custom Data, RealtimeComponent. If you need to test logic that does not depend on the live model or networking, you could isolate that logic into plain C# classes and test them in EditMode, but anything involving the model or synchronization must be done in PlayMode. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@412870643533479936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?