补齐 package Tests 第一刀

This commit is contained in:
JSD\13999
2026-06-06 16:14:17 +08:00
parent 0930e7c173
commit 7b2243a40b
13 changed files with 334 additions and 169 deletions

View File

@@ -0,0 +1,26 @@
{
"name": "FlowScope.PackageTests.EditMode",
"rootNamespace": "FlowScope.PackageTests.EditMode",
"references": [
"FlowScope.Runtime",
"FlowScope.Addressables",
"R3.Unity"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"R3.dll",
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"optionalUnityReferences": [
"TestAssemblies"
],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e213b3e4bd60472087919ca2efba94bc
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
using System.Threading;
using System.Threading.Tasks;
using FlowScope.Addressables;
using FlowScope.Container;
using FlowScope.Resources;
using NUnit.Framework;
namespace FlowScope.PackageTests.EditMode
{
public sealed class PackageSmokeTests
{
[Test]
public void PackageAssemblies_CanBeReferencedFromPackageTests()
{
var container = new Container();
var backend = new AddressablesResourceBackend();
IResourceService resources = new ResourceService(new ImmediateBackend());
container.RegisterInstance(resources);
Assert.AreEqual("Addressables", backend.Name);
Assert.AreSame(resources, container.Resolve<IResourceService>());
container.Dispose();
}
[Test]
public void ResourceService_LoadAsync_CanRunInsidePackageTestAssembly()
{
var backend = new ImmediateBackend();
var service = new ResourceService(backend);
using var handle = service
.LoadAsync<TestAsset>("package-smoke", CancellationToken.None)
.GetAwaiter()
.GetResult();
Assert.That(handle.Asset, Is.Not.Null);
Assert.AreEqual(1, backend.LoadCalls);
handle.Dispose();
Assert.AreEqual(1, backend.ReleaseCalls);
}
private sealed class ImmediateBackend : IResourceBackend
{
public string Name => "Immediate";
public int LoadCalls { get; private set; }
public int ReleaseCalls { get; private set; }
public Task<T> LoadAsync<T>(string key, CancellationToken cancellationToken)
where T : class
{
LoadCalls++;
return Task.FromResult(new TestAsset() as T);
}
public void Release<T>(string key, T asset)
where T : class
{
ReleaseCalls++;
}
}
private sealed class TestAsset
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: adbf3a7109f64fea8a6c75febc85d0f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: