<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — destroying instances during unit and integration tests]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=869&amp;type=atom" />
	<updated>2018-07-31T12:54:07Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=869</id>
		<entry>
			<title type="html"><![CDATA[Re: destroying instances during unit and integration tests]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3741#p3741" />
			<content type="html"><![CDATA[<p>Thanks for taking a look, Alex. Turns out that my problem was not instantiating the map GameObject after loading it as a resource. I&#039;ve been using Zenject for loading prefabs and forgot how to do it the standard way. For posterity, here&#039;s how to load the map as part of a Unity play mode test:</p><div class="codebox"><pre><code>        [UnityTest]
        public IEnumerator TestMapLoaded()
        {
            var mapObj = Resources.Load(&quot;Prefabs/UI/Map&quot;) as GameObject;
            Assert.IsNotNull(mapObj);

            var mapInstance = GameObject.Instantiate(mapObj);
            var camera = mapInstance.AddComponent&lt;Camera&gt;();
            Assert.True(mapInstance.activeInHierarchy);
            var maps = mapInstance.GetComponent&lt;OnlineMaps&gt;();
            Assert.IsNotNull(maps);
            var tileset = mapInstance.GetComponent&lt;OnlineMapsTileSetControl&gt;();
            Assert.IsNotNull(tileset);
            tileset.activeCamera = camera;
            Assert.IsNotNull(tileset);
            Assert.True(maps.isActiveAndEnabled);
            Assert.IsNotNull(OnlineMaps.instance);
            Assert.IsNotNull(tileset.activeCamera);
            yield return null;
        }</code></pre></div><p>Tim</p>]]></content>
			<author>
				<name><![CDATA[movestill]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=358</uri>
			</author>
			<updated>2018-07-31T12:54:07Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3741#p3741</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: destroying instances during unit and integration tests]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3739#p3739" />
			<content type="html"><![CDATA[<p>Here is the explanation:<br /><a href="https://answers.unity.com/questions/698664/is-there-a-way-to-ensure-awake-is-called-in-unit-t.html">https://answers.unity.com/questions/698 … nit-t.html</a></p><p>Unfortunately, I&#039;m not a big helper in unit testing, because I do not use it in Unity.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2018-07-30T21:30:03Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3739#p3739</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: destroying instances during unit and integration tests]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3737#p3737" />
			<content type="html"><![CDATA[<p>Thanks for the prompt reply. Any idea why Awake() isn&#039;t called after instantiating the prefab? In the prefab, the GameObject is active as is its OnlineMaps and OnlineMapsTileSetControl components. </p><p>Actually, after looking further, it seems like the instantiated prefab can&#039;t be activated for some reason.</p><p>Here&#039;s bare minimum test code using Unity 2017.3 and OnlineMaps 2.5.30.1:</p><div class="codebox"><pre><code>    [TestFixture]
    public class MapTest
    {
        [UnityTest]
        public IEnumerator TestMap()
        {
            var mapObj = Resources.Load(&quot;Prefabs/UI/Map&quot;) as GameObject;
            Assert.IsNotNull(mapObj);
            yield return null;
            mapObj.SetActive(true);
            yield return null;

// This assert fails.

            Assert.True(mapObj.activeInHierarchy);
        }
    }</code></pre></div><p>Thanks,<br />Tim</p>]]></content>
			<author>
				<name><![CDATA[movestill]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=358</uri>
			</author>
			<updated>2018-07-30T18:25:06Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3737#p3737</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: destroying instances during unit and integration tests]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3736#p3736" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Just destroy the map GameObject, and then create a new instance from the prefab.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2018-07-30T16:26:09Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3736#p3736</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[destroying instances during unit and integration tests]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=3735#p3735" />
			<content type="html"><![CDATA[<p>Is there an easy way to destroy all the various instances to ensure each test starts with a clean state? At first glance, looks like we use the instance properties of these classes:</p><p>OnlineMaps<br />OnlneMapsControlBase3D<br />OnlineMapsTileSetControl</p><p>Thanks,<br />Tim</p>]]></content>
			<author>
				<name><![CDATA[movestill]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=358</uri>
			</author>
			<updated>2018-07-30T16:21:16Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=3735#p3735</id>
		</entry>
</feed>
