Class ScrollRectTests
Inheritance
ScrollRectTests
Implements
IPrebuildSetup
Assembly: UnityEngine.UI.Tests.dll
public class ScrollRectTests : IPrebuildSetup
Methods
Declaration
[Test]
[TestCase(new object[] { true, true, 2, 4, -2, -2 }, TestName = "Should clamp offset")]
[TestCase(new object[] { false, true, 2, 4, 0, -2 }, TestName = "Vertical should clamp offset on one axis")]
[TestCase(new object[] { true, false, 2, 4, -2, 0 }, TestName = "Horizontal should clamp offset on one axis")]
[TestCase(new object[] { false, false, 2, 4, 0, 0 }, TestName = "No axis should not clamp offset")]
[TestCase(new object[] { true, true, 8, 10, 2, 2 }, TestName = "Should clamp negative offset")]
[TestCase(new object[] { false, true, 8, 10, 0, 2 }, TestName = "Vertical should clamp negative offset on one axis")]
[TestCase(new object[] { true, false, 8, 10, 2, 0 }, TestName = "Horizontal should clamp negative offset on one axis")]
[TestCase(new object[] { false, false, 8, 10, 0, 0 }, TestName = "No axis should not clamp negative offset")]
public void CalculateOffsetShouldClamp(bool horizontal, bool vertical, int viewX, float viewY, float resX, float resY)
Parameters
Declaration
[Test]
[TestCase(new object[] { true, true, 2, 4, -2, -2 }, TestName = "Should clamp offset")]
[TestCase(new object[] { false, true, 2, 4, 0, -2 }, TestName = "Vertical should clamp offset on one axis")]
[TestCase(new object[] { true, false, 2, 4, -2, 0 }, TestName = "Horizontal should clamp offset on one axis")]
[TestCase(new object[] { false, false, 2, 4, 0, 0 }, TestName = "No axis should not clamp offset")]
[TestCase(new object[] { true, true, 8, 10, 2, 2 }, TestName = "Should clamp negative offset")]
[TestCase(new object[] { false, true, 8, 10, 0, 2 }, TestName = "Vertical should clamp negative offset on one axis")]
[TestCase(new object[] { true, false, 8, 10, 2, 0 }, TestName = "Horizontal should clamp negative offset on one axis")]
[TestCase(new object[] { false, false, 8, 10, 0, 0 }, TestName = "No axis should not clamp negative offset")]
public void CalculateOffsetUnrestrictedShouldNotClamp(bool horizontal, bool vertical, int viewX, float viewY, float resX, float resY)
Parameters
Declaration
[Test]
public void GetBoundsShouldEncapsulateAllCorners()
Declaration
[UnityTest]
public IEnumerator LateUpdateWithElasticNoOffsetShouldZeroVelocity()
Returns
Declaration
[UnityTest]
[Ignore("Fails")]
public IEnumerator LateUpdateWithElasticShouldDecelerate()
Returns
Declaration
[UnityTest]
public IEnumerator LateUpdateWithInertiaShouldDecelerate()
Returns
Declaration
[UnityTest]
public IEnumerator LateUpdateWithoutInertiaOrElasticShouldZeroVelocity()
Returns
Declaration
[Test]
[TestCase(PointerEventData.InputButton.Left, true, true)]
[TestCase(PointerEventData.InputButton.Left, false, false)]
[TestCase(PointerEventData.InputButton.Right, true, false)]
[TestCase(PointerEventData.InputButton.Middle, true, false)]
public void LeftClickShouldStartDrag(PointerEventData.InputButton button, bool active, bool expectedIsDragging)
Parameters
Declaration
[Test]
[TestCase(PointerEventData.InputButton.Left, true, false)]
[TestCase(PointerEventData.InputButton.Left, false, false)]
[TestCase(PointerEventData.InputButton.Right, false, false)]
[TestCase(PointerEventData.InputButton.Right, true, true)]
[TestCase(PointerEventData.InputButton.Middle, true, true)]
[TestCase(PointerEventData.InputButton.Middle, false, false)]
public void LeftClickUpShouldEndDrag(PointerEventData.InputButton button, bool active, bool expectedIsDragging)
Parameters
Declaration
[UnityTest]
[Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-42513")]
[TestCase(true, ExpectedResult = null)]
[TestCase(false, ExpectedResult = null)]
public IEnumerator OnDisableShouldRemoveListeners(bool isHorizontal)
Parameters
Type |
Name |
Description |
bool |
isHorizontal |
|
Returns
Declaration
[UnityTest]
[Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-42513")]
[TestCase(true, ExpectedResult = null)]
[TestCase(false, ExpectedResult = null)]
public IEnumerator OnEnableShouldAddListeners(bool isHorizontal)
Parameters
Type |
Name |
Description |
bool |
isHorizontal |
|
Returns
OnScrollClampedShouldClampContentAnchoredPosition(MovementType, float, float)
Declaration
[Test]
[Ignore("Tests fail without mocking")]
[TestCase(ScrollRect.MovementType.Clamped, 1, 1)]
[TestCase(ScrollRect.MovementType.Unrestricted, 150, 150)]
[TestCase(ScrollRect.MovementType.Elastic, 150, 150)]
public void OnScrollClampedShouldClampContentAnchoredPosition(ScrollRect.MovementType movementType, float anchoredPosX, float anchoredPosY)
Parameters
OnScrollClampedShouldMoveContentAnchoredPosition(int, int, bool, bool, int, int)
Declaration
[Test]
[TestCase(new object[] { 1, 1, true, true, 1, -1 }, TestName = "Horizontal and vertical scroll")]
[TestCase(new object[] { 1, 1, false, true, 0, -1 }, TestName = "Vertical scroll")]
[TestCase(new object[] { 1, 1, true, false, 1, 0 }, TestName = "Horizontal scroll")]
public void OnScrollClampedShouldMoveContentAnchoredPosition(int scrollDeltaX, int scrollDeltaY, bool horizontal, bool vertical, int expectedPosX, int expectedPosY)
Parameters
Type |
Name |
Description |
int |
scrollDeltaX |
|
int |
scrollDeltaY |
|
bool |
horizontal |
|
bool |
vertical |
|
int |
expectedPosX |
|
int |
expectedPosY |
|
Declaration
[OneTimeTearDown]
public void OneTimeTearDown()
Declaration
[Test]
[TestCase(PointerEventData.InputButton.Left, true)]
[TestCase(PointerEventData.InputButton.Right, false)]
[TestCase(PointerEventData.InputButton.Middle, false)]
public void PotentialDragNeedsLeftClick(PointerEventData.InputButton button, bool expectedEqualsZero)
Parameters
SetNormalizedPositionShouldSetContentLocalPosition()
Declaration
[Test]
public void SetNormalizedPositionShouldSetContentLocalPosition()
Declaration
[Test]
[Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-42513")]
[TestCase(true)]
[TestCase(false)]
public void SettingScrollbarShouldRemoveThenAddListeners(bool testHorizontal)
Parameters
Type |
Name |
Description |
bool |
testHorizontal |
|
Implement this method to call actions automatically before the build process.
Declaration
[TestFixture]
public class CreateSpriteTest : IPrebuildSetup
{
Texture2D m_Texture;
Sprite m_Sprite;
public void Setup()
{
#if UNITY_EDITOR
var spritePath = "Assets/Resources/Circle.png";
var ti = UnityEditor.AssetImporter.GetAtPath(spritePath) as UnityEditor.TextureImporter;
ti.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed;
ti.SaveAndReimport();
#endif
}
[SetUp]
public void SetUpTest()
{
m_Texture = Resources.Load<Texture2D>("Circle");
}
[Test]
public void WhenNullTextureIsPassed_CreateShouldReturnNullSprite()
{
// Check with Valid Texture.
LogAssert.Expect(LogType.Log, "Circle Sprite Created");
Sprite.Create(m_Texture, new Rect(0, 0, m_Texture.width, m_Texture.height), new Vector2(0.5f, 0.5f));
Debug.Log("Circle Sprite Created");
// Check with NULL Texture. Should return NULL Sprite.
m_Sprite = Sprite.Create(null, new Rect(0, 0, m_Texture.width, m_Texture.height), new Vector2(0.5f, 0.5f));
Assert.That(m_Sprite, Is.Null, "Sprite created with null texture should be null");
}
}
> **Tip**: Use `#if UNITY_EDITOR` if you want to access Editor only APIs, but the setup/cleanup is inside a **Play Mode** assembly.
Declaration
[TearDown]
public void TearDown()
Declaration
[SetUp]
public void TestSetup()
Declaration
[Test]
public void UpdateBoundsShouldPad()
Implements
UnityEngine.TestTools.IPrebuildSetup