RuntimeUnitTestToolkit for Unity(English)

16
RuntimeUnitTestToolk it 2017/03/04 – Yoshifumi Kawai / neuecc

Transcript of RuntimeUnitTestToolkit for Unity(English)

Page 1: RuntimeUnitTestToolkit for Unity(English)

RuntimeUnitTestToolkit

2017/03/04 – Yoshifumi Kawai / neuecc

Page 2: RuntimeUnitTestToolkit for Unity(English)

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)

Page 3: RuntimeUnitTestToolkit for Unity(English)

UnitTest

Page 4: RuntimeUnitTestToolkit for Unity(English)

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

Page 5: RuntimeUnitTestToolkit for Unity(English)

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

Page 6: RuntimeUnitTestToolkit for Unity(English)

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!!!

Page 7: RuntimeUnitTestToolkit for Unity(English)

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

Page 8: RuntimeUnitTestToolkit for Unity(English)

RuntimeUnitTestToolkit

Page 9: RuntimeUnitTestToolkit for Unity(English)

Demo…

Page 10: RuntimeUnitTestToolkit for Unity(English)

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...

Page 11: RuntimeUnitTestToolkit for Unity(English)

// 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

Page 12: RuntimeUnitTestToolkit for Unity(English)

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

Page 13: RuntimeUnitTestToolkit for Unity(English)

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

Page 14: RuntimeUnitTestToolkit for Unity(English)

Conclusion

Page 15: RuntimeUnitTestToolkit for Unity(English)

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

Page 16: RuntimeUnitTestToolkit for Unity(English)

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?