Skip to content

Commit f2aec78

Browse files
authored
Merge pull request #304 from Unity-Technologies/Uni-38306-FixingAutoUpdaterInUnitTest
Fix of the unit tests, taking into account the Auto Updater toggle.
2 parents 15333ce + f8d5c60 commit f2aec78

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,18 @@ public static void UpdateLinkedPrefab(GameObject prefabInstance)
237237
// Launch the manual update UI to allow the user to fix
238238
// renamed nodes (or auto-update if there's nothing to rename).
239239
var fbxPrefabUtility = new FbxPrefabUtility(fbxPrefabComponent);
240-
ManualUpdateEditorWindow window = (ManualUpdateEditorWindow)EditorWindow.GetWindow(typeof(ManualUpdateEditorWindow));
241-
window.Init(fbxPrefabUtility, fbxPrefabComponent);
242-
window.Show();
240+
241+
if (FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled || runningUnitTest)
242+
{
243+
fbxPrefabUtility.SyncPrefab();
244+
}
245+
else
246+
{
247+
ManualUpdateEditorWindow window = (ManualUpdateEditorWindow)EditorWindow.GetWindow(typeof(ManualUpdateEditorWindow));
248+
window.Init(fbxPrefabUtility, fbxPrefabComponent);
249+
window.Show();
250+
}
251+
243252
}
244253
}
245254

Assets/FbxExporters/Editor/UnitTests/DefaultSelectionTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public class DefaultSelectionTest : ExporterTestBase
1919
protected bool m_centerObjectsSetting;
2020

2121
[SetUp]
22-
public void Init ()
22+
public override void Init ()
2323
{
24+
base.Init();
2425
m_centerObjectsSetting = FbxExporters.EditorTools.ExportSettings.instance.centerObjects;
2526
}
2627

Assets/FbxExporters/Editor/UnitTests/ExportPerformanceTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public class ExportPerformanceTest : ExporterTestBase
1818
private GameObject m_toExport;
1919

2020
[SetUp]
21-
public void Init()
21+
public override void Init()
2222
{
23+
base.Init();
2324
m_stopwatch = new Stopwatch ();
2425
m_toExport = CreateGameObjectToExport ();
2526
}

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace FbxExporters.UnitTests
99
{
1010
public abstract class ExporterTestBase
1111
{
12+
bool isAutoUpdaterOn;
1213
/// <summary>
1314
/// Sleep an amount of time (in ms) so we can safely assume that the
1415
/// timestamp on an fbx will change.
@@ -200,8 +201,19 @@ public virtual void Term ()
200201
// Delete the directory on the next editor update. Otherwise,
201202
// prefabs don't get deleted and the directory delete fails.
202203
EditorApplication.update += DeleteOnNextUpdate;
204+
205+
// Put back the initial setting for the auto-updater toggle
206+
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;
203207
}
204208

209+
[SetUp]
210+
public virtual void Init()
211+
{
212+
isAutoUpdaterOn = FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled;
213+
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = true;
214+
}
215+
216+
205217
/// <summary>
206218
/// Exports the Objects in selected.
207219
/// </summary>

Assets/FbxExporters/Editor/UnitTests/FbxPrefabAutoUpdaterTest.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public class FbxPrefabAutoUpdaterTest : ExporterTestBase
1919
string m_prefabPath;
2020

2121
[SetUp]
22-
public void Init ()
22+
public override void Init ()
2323
{
24+
base.Init();
2425
var capsule = GameObject.CreatePrimitive (PrimitiveType.Capsule);
2526
m_fbx = ExportSelection (capsule);
2627
m_fbxPath = AssetDatabase.GetAssetPath (m_fbx);
@@ -175,14 +176,6 @@ public void TestNameMapping()
175176

176177
public class FbxPrefabAutoUpdaterRemappingTest : ExporterTestBase
177178
{
178-
bool isAutoUpdaterOn;
179-
[SetUp]
180-
public void Init()
181-
{
182-
isAutoUpdaterOn = FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled;
183-
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = true;
184-
}
185-
186179
[Test]
187180
public void RemappingTest()
188181
{
@@ -228,19 +221,15 @@ public void RemappingTest()
228221
Assert.IsTrue(cubePrefabInstance.transform.GetChild(0).name == "SphereFBX");
229222
Assert.IsTrue(cubePrefabInstance.transform.GetChild(0).GetComponent<MeshFilter>().sharedMesh != null);
230223
}
231-
[TearDown]
232-
public void stopTest()
233-
{
234-
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = isAutoUpdaterOn;
235-
}
236224
}
237225

238226
public class FbxPrefabAutoUpdaterToggleTest : ExporterTestBase
239227
{
240228
bool isAutoUpdaterOn;
241229
[SetUp]
242-
public void Init()
230+
public override void Init()
243231
{
232+
base.Init();
244233
// Save the initial setting for the auto updater toggle and disable it for the unit test
245234
isAutoUpdaterOn = FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled;
246235
FbxExporters.EditorTools.ExportSettings.instance.autoUpdaterEnabled = false;

Assets/FbxExporters/Editor/UnitTests/FbxPrefabTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public static void AssertAreDifferent(
146146
}
147147

148148
[SetUp]
149-
public void Init() {
149+
public override void Init() {
150+
base.Init();
150151
// Create a test hierarchy. It has unique names.
151152
m_original = CreateHierarchy("FbxPrefabTestRoot");
152153
m_originalRep = Rep(m_original);

0 commit comments

Comments
 (0)