Skip to content

Commit b299726

Browse files
Adding some comments based on study of the test framework
The original developer created an interesting testing approach but I felt it needed some clues for how it works.
1 parent 95e5cf7 commit b299726

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

TestCommon/TestFixtures.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace UnityDataTools.TestCommon;
66

7+
// Base class that facilitates iterating through sub-sub-folders
8+
// inside the Data location. E.g. GetContexts("AssetBundles")
9+
// finds "TestCommon/Data/AssetBundles/2019.4.0f1", "TestCommon/Data/AssetBundles/2020.3.0f1" etc.
710
public class BaseTestFixture
811
{
912
protected Context Context { get; }
@@ -15,6 +18,8 @@ public BaseTestFixture(Context context)
1518
Context = context;
1619
}
1720

21+
// Tests that have files that record the expected results for each version
22+
// of Unity can override this method to regenerate those expected results.
1823
protected virtual void OnLoadExpectedData(Context context)
1924
{
2025
}
@@ -23,6 +28,9 @@ protected virtual void OnLoadExpectedData(Context context)
2328
public void LoadExpectedData()
2429
{
2530
OnLoadExpectedData(Context);
31+
32+
// Load json file with the expected results for a test based on
33+
// folder structure convention (e.g. ExpectedData/<UnityVersion>/ExpectedVersions.json)
2634
Context.ExpectedData.Load(Context.ExpectedDataFolder);
2735
}
2836

@@ -47,6 +55,9 @@ protected static IEnumerable<Context> GetContexts(string dataFolder)
4755
}
4856
}
4957

58+
// Test fixture that repeats the tests for each folder inside TestCommon/Data/AssetBundles.
59+
// Each sub-folder is expected to have results of an AssetBundle build repeated with a
60+
// different version of Unity.
5061
[TestFixtureSource(typeof(AssetBundleTestFixture), nameof(GetContexts))]
5162
public class AssetBundleTestFixture : BaseTestFixture
5263
{

UnityDataTool.Tests/ExpectedDataGenerator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
namespace UnityDataTools.UnityDataTool.Tests;
77

8+
// Collect and record the current output returned by the same UnityDataTool commands
9+
// that the tests will run. Once saved these become the reference data, and if the output
10+
// changes the tests will fail. So this can be repeated if there is an "expected" change
11+
// in the output.
812
public static class ExpectedDataGenerator
913
{
1014
public static void Generate(Context context)
@@ -71,6 +75,9 @@ public static void Generate(Context context)
7175
var csprojFolder = Directory.GetParent(context.TestDataFolder).Parent.Parent.Parent.FullName;
7276
var outputFolder = Path.Combine(csprojFolder, "ExpectedData", context.UnityDataVersion);
7377

78+
expectedData.Save(outputFolder);
79+
80+
// Also take a snapshot of the output of running "dump" commands on the test file "assetbundle"
7481
Directory.CreateDirectory(outputFolder);
7582

7683
var dumpPath = Path.Combine(outputFolder, "dump");
@@ -80,7 +87,5 @@ public static void Generate(Context context)
8087
dumpPath = Path.Combine(outputFolder, "dump-s");
8188
Directory.CreateDirectory(dumpPath);
8289
Program.Main(new string[] { "dump", Path.Combine(context.UnityDataFolder, "assetbundle"), "-o", dumpPath, "-s" });
83-
84-
expectedData.Save(outputFolder);
8590
}
8691
}

0 commit comments

Comments
 (0)