70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AsteroidGame.Entities;
|
|
using NUnit.Framework;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.TestTools;
|
|
using Assert = UnityEngine.Assertions.Assert;
|
|
|
|
public class TurretTestScript : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<Turret> _turrets;
|
|
[SerializeField] private EnemyBase _enemy;
|
|
|
|
[UnitySetUp]
|
|
public IEnumerator LoadScene()
|
|
{
|
|
// Load the scene asynchronously and wait until it's fully loaded
|
|
var asyncLoad = SceneManager.LoadSceneAsync("TurretTestScene");
|
|
while (!asyncLoad.isDone)
|
|
{
|
|
yield return null;
|
|
}
|
|
|
|
_turrets = new();
|
|
_turrets = FindObjectsOfType<Turret>().ToList();
|
|
|
|
_enemy = new();
|
|
_enemy = FindObjectOfType<EnemyBase>();
|
|
}
|
|
|
|
// // A Test behaves as an ordinary method
|
|
// [Test]
|
|
// public void NewTestScriptSimplePasses()
|
|
// {
|
|
// // Use the Assert class to test conditions
|
|
// }
|
|
//
|
|
// // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
|
// // `yield return null;` to skip a frame.
|
|
// [UnityTest]
|
|
// public IEnumerator NewTestScriptWithEnumeratorPasses()
|
|
// {
|
|
// // Use the Assert class to test conditions.
|
|
// // Use yield to skip a frame.
|
|
// yield return null;
|
|
// }
|
|
|
|
[UnityTest]
|
|
public IEnumerator OnlyOneTurretGetsTheKill()
|
|
{
|
|
var totalKillCount = 0;
|
|
if (_enemy != null)
|
|
{
|
|
yield return null;
|
|
}
|
|
else
|
|
{
|
|
foreach (var turret in _turrets)
|
|
{
|
|
totalKillCount += turret.Kills;
|
|
}
|
|
}
|
|
|
|
Assert.IsTrue(totalKillCount == 1);
|
|
}
|
|
} |