UI相关优化补充
This commit is contained in:
49
Assets/Tests/PlayMode/RequiredFieldValidatorTests.cs
Normal file
49
Assets/Tests/PlayMode/RequiredFieldValidatorTests.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
|
||||
namespace BaseGames.Tests.PlayMode
|
||||
{
|
||||
/// <summary>
|
||||
/// RequiredFieldValidator 反射扫描测试。
|
||||
/// </summary>
|
||||
public class RequiredFieldValidatorTests
|
||||
{
|
||||
private class Sample : MonoBehaviour
|
||||
{
|
||||
[RequiredField] public GameObject Required;
|
||||
[RequiredField("提示文本")] public string RequiredString;
|
||||
public GameObject Optional;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MissingField_LogsWarning()
|
||||
{
|
||||
var go = new GameObject("ReqHost");
|
||||
var s = go.AddComponent<Sample>();
|
||||
s.Required = null;
|
||||
s.RequiredString = "";
|
||||
|
||||
// 期待两条警告(Required + RequiredString)
|
||||
UnityEngine.TestTools.LogAssert.Expect(LogType.Warning,
|
||||
new System.Text.RegularExpressions.Regex(@"\[RequiredField\] Sample\.Required.*"));
|
||||
UnityEngine.TestTools.LogAssert.Expect(LogType.Warning,
|
||||
new System.Text.RegularExpressions.Regex(@"\[RequiredField\] Sample\.RequiredString.*"));
|
||||
RequiredFieldValidator.ValidateAll(s);
|
||||
|
||||
Object.DestroyImmediate(go);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FilledField_NoWarning()
|
||||
{
|
||||
var go = new GameObject("ReqHost2");
|
||||
var s = go.AddComponent<Sample>();
|
||||
s.Required = go;
|
||||
s.RequiredString = "ok";
|
||||
|
||||
RequiredFieldValidator.ValidateAll(s); // 不应有警告
|
||||
Object.DestroyImmediate(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user