Loading...
Loading...
Use when writing or running Unity tests, including EditMode tests, PlayMode tests, performance testing, and code coverage
npx skill4agent add dmitriyyukhanov/claude-plugins unity-testingPackages/manifest.jsoncom.unity.test-frameworkIEnumeratorasync TaskTests/
├── Editor/
│ ├── <Company>.<Package>.Editor.Tests.asmdef
│ └── FeatureTests.cs
└── Runtime/
├── <Company>.<Package>.Tests.asmdef
└── FeaturePlayModeTests.csusing NUnit.Framework;
using UnityEngine;
[TestFixture]
public class FeatureEditorTests
{
[SetUp]
public void Setup()
{
// Arrange common test setup
}
[TearDown]
public void TearDown()
{
// Cleanup
}
[Test]
public void MethodName_Condition_ExpectedResult()
{
// Arrange
var sut = new SystemUnderTest();
var expected = 42;
// Act
var result = sut.DoSomething();
// Assert
Assert.AreEqual(expected, result);
}
}using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class FeaturePlayModeTests
{
private GameObject _testObject;
[SetUp]
public void Setup()
{
_testObject = new GameObject("TestObject");
}
[TearDown]
public void TearDown()
{
// Use Destroy for PlayMode tests (DestroyImmediate for EditMode tests)
Object.Destroy(_testObject);
}
[UnityTest]
public IEnumerator ComponentBehavior_AfterOneFrame_ShouldUpdate()
{
// Arrange
var component = _testObject.AddComponent<TestComponent>();
// Act
yield return null; // Wait one frame
// Assert
Assert.IsTrue(component.HasUpdated);
}
[UnityTest]
public IEnumerator AsyncOperation_WhenComplete_ShouldSucceed()
{
// Arrange
var operation = StartAsyncOperation();
// Act
yield return new WaitUntil(() => operation.IsDone);
// Assert
Assert.IsTrue(operation.Success);
}
}[UnityTest]IEnumerator1.3+UnityTestasync Task2023.1+6+UnityEngine.AwaitableAwaitableTaskIEnumeratorAwaitableusing System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class FeatureAsyncPlayModeTests
{
[UnityTest]
public async Task ComponentBehavior_AfterOneFrame_ShouldUpdate()
{
var go = new GameObject("TestObject");
var component = go.AddComponent<TestComponent>();
#if UNITY_6000_0_OR_NEWER
await Awaitable.NextFrameAsync();
#else
await Task.Yield();
#endif
Assert.IsTrue(component.HasUpdated);
Object.Destroy(go);
}
}using NUnit.Framework;
using Unity.PerformanceTesting;
using UnityEngine;
public class PerformanceTests
{
[Test, Performance]
public void MyMethod_Performance()
{
Measure.Method(() =>
{
// Code to measure
MyExpensiveMethod();
})
.WarmupCount(10)
.MeasurementCount(100)
.Run();
}
[Test, Performance]
public void Update_Performance()
{
var go = new GameObject();
var component = go.AddComponent<MyComponent>();
Measure.Frames()
.WarmupCount(10)
.MeasurementCount(100)
.Run();
Object.DestroyImmediate(go);
}
}com.unity.testtools.codecoverageUnity -batchmode -projectPath "$(pwd)" -runTests -testPlatform EditMode -enableCodeCoverage -coverageResultsPath ./CodeCoverage -testResults ./TestResults/editmode.xml -quit[SetUp][TearDown]MethodName_Condition_ExpectedResultGetUser_WhenNotFound_ReturnsNullUnityEngine.TestTools.LogAssert[Test]
public void MethodName_Condition_ExpectedResult()
{
// Arrange - Setup test data and dependencies
var input = CreateTestInput();
var expected = CreateExpectedOutput();
// Act - Execute the code under test
var result = systemUnderTest.Process(input);
// Assert - Verify the outcome
Assert.AreEqual(expected, result);
}