Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #28

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions Tests/Runtime/Constraints/DestroyedConstraintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
// This software is released under the MIT License.

using System;
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using UnityEngine;
using Object = UnityEngine.Object;

namespace TestHelper.Constraints
{
[SuppressMessage("ReSharper", "AccessToStaticMemberViaDerivedType")]
public class DestroyedConstraintTest
{
private static GameObject CreateDestroyedObject()
{
var gameObject = new GameObject();
Object.DestroyImmediate(gameObject);
GameObject.DestroyImmediate(gameObject);
return gameObject;
}

Expand All @@ -30,67 +31,48 @@ public void IsDestroyed_NotDestroyedGameObject_Failure()
{
var actual = new GameObject("Foo");

try
Assert.That(() =>
{
Assert.That(actual, Is.Destroyed);
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <Foo (UnityEngine.GameObject)>{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <Foo (UnityEngine.GameObject)>{Environment.NewLine}"));
}

[Test]
public void IsDestroyed_Null_Failure()
{
GameObject actual = null;

try
Assert.That(() =>
{
// ReSharper disable once ExpressionIsAlwaysNull
Assert.That(actual, Is.Destroyed);
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: null{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: null{Environment.NewLine}"));
}

[Test]
public void IsDestroyed_NotGameObject_Failure()
{
var actual = string.Empty;

try
Assert.That(() =>
{
Assert.That(actual, Is.Destroyed);
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <string.Empty>{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: destroyed GameObject{Environment.NewLine} But was: <string.Empty>{Environment.NewLine}"));
}

[Test]
public void IsNotDestroyed_DestroyedGameObject_Failure()
{
var actual = CreateDestroyedObject();

try
Assert.That(() =>
{
Assert.That(actual, Is.Not.Destroyed()); // Note: Use it in method style when with operators
Assert.Fail();
}
catch (AssertionException e)
{
Assert.That(e.Message, Is.EqualTo(
$" Expected: not destroyed GameObject{Environment.NewLine} But was: <null>{Environment.NewLine}"));
}
}, Throws.TypeOf<AssertionException>().With.Message.EqualTo(
$" Expected: not destroyed GameObject{Environment.NewLine} But was: <null>{Environment.NewLine}"));
}

[Test]
Expand Down