RuntimeUnitTestToolkit for Unity(English)
-
Upload
yoshifumi-kawai -
Category
Technology
-
view
644 -
download
0
Transcript of RuntimeUnitTestToolkit for Unity(English)
RuntimeUnitTestToolkit
2017/03/04 – Yoshifumi Kawai / neuecc
Self IntroductionWorkYoshifumi Kawai - Grani, Inc Director/CTOhttp://grani.jp/Grani is Top C# Mobile Game Studio in JapanC# 6.0 + .NET Framework 4.6 + UnityPrivateMicrosoft MVP for Visual C# since 2011Web http://neue.cc/Twitter @neueccUniRx(Reactive Extensions for Unity) - https://github.com/neuecc/UniRx (★1310)
UnitTest
MSTest or xUnit.netMSTest, which was included in Visual Studio for a long time used.Recently, xUnit.net is also used because .NET Core, IDE independentxUnit.netUnitTest framework which was used Roslyn(C# Compiler), corefx, etcStandard on Microsoft’s OSSNUnitStandard on Mono
UnitTest in .NET
Visual Studio UINo needs to Visual Studio ExtensionImport from NuGet,Visual Studio detect there testsMore multi functionalParameterized TestGood fixture, better than MSTestMSTest is dead
xUnit.net is better than MSTest
Standard on NUnit basedtoolSounds Good !Great test explorer window by editor extensionBut...It only run on Unity EditorIt only run on Unity EditorIt only run on Unity Editor
UnitTest in Unity
Ciritcal Issues!!!
I want to run on IL2CPPI’m creating some libraries- UniRx, ZeroFormatter, MessagePack for C#, etc...supports IL2CPPOften not working with IL2CPP- Many Generics- Reflection- Optimized code on C# Specification- IL Generation
Actual Machine Test
RuntimeUnitTestToolkit
Demo…
Succeed, GreenFailed, Red and show info on log
window
This is simple unity scene, can check on Unity Editor’s
GameWindows and transport to Windows, iOS, Android, etc...
// make unit test on plain C# classpublic class SampleGroup{ // all public methods are automatically registered in test group public void SumTest() { var x = int.Parse("100"); var y = int.Parse("200");
// using RuntimeUnitTestToolkit; // 'Is' is Assertion method, same as Assert(actual, expected) (x + y).Is(300); }}
Write Unit test on plain class and plain public method
public class SampleGroup{ // return type 'IEnumerator' is marked as async test method public IEnumerator AsyncTest() { var testObject = new GameObject("Test");
// wait asynchronous coroutine(UniRx coroutine runnner) yield return MainThreadDispatcher.StartCoroutine(MoveToRight(testObject));
// assrtion testObject.transform.position.x.Is(60);
GameObject.Destroy(testObject); }
IEnumerator MoveToRight(GameObject o) { for (int i = 0; i < 60; i++) { var p = o.transform.position; p.x += 1; o.transform.position = p; yield return null; } }}
also supports asynchronous test
public static class UnitTestLoader{ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] public static void Register() { // setup created test class to RegisterAllMethods<T> UnitTest.RegisterAllMethods<SampleGroup>(); // and add other classes }}
New Group is added on playtime
finally register test classes on test manager
Conclusion
UniRx is supported by RuntimeUnitTestToolkitBuild on Unity Cloud Build -> Check iOS -> All GreenSupports IL2CPP!Released in GitHubhttps://github.com/neuecc/RuntimeUnitTestToolkit.unitypackages was published on Releases page
already used on UniRx
Focus on play time testShould support playing time(Editting time test is very bad...)Supports Asynchronous testShould support IEnumerator(Coroutine)Async resource load, finished after xxx, etc...Actual machine testTest explorer on Unity Edtor is goodI needs same ui on playing scene
Unity Test should supports...
Unity 5.6(Beta) will supports it?