Giter VIP home page Giter VIP logo

runtimeunittesttoolkit's Introduction

RuntimeUnitTestToolkit

Unity unit test framework focused on run play time and actual machine

image

Why needs this?

Presentation Slide - RuntimeUnitTestToolkit for Unity

Unity Unit Test is not supported runtime unit test. IL2CPP or other machine specific issue is a serious issue. We should check it.

How to use?

get .unitypackage on releases page.

Open RuntimeUnitTestToolkit/UnitTest.scene, it is test explorer.

Write first test class.

// make unit test on plain C# class
public 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);
    }

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

finally register test classes on test manager

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

play UnitTest scene

image

Assertion API

Standard API(static Assert methods)

  • Assert.AreEqual
  • Assert.AreNotEqual
  • Assert.IsTrue
  • Assert.IsNull
  • Assert.IsNotNull
  • Assert.Fail
  • Assert.AreSame
  • Assert.AreNotSame
  • Assert.IsInstanceOfType
  • Assert.IsNotInstanceOfType
  • Assert.Catch
  • Assert.Throws
  • Assert.DoesNotThrow
  • CollectionAssert.AreEqual
  • CollectionAssert.AreNotEqual

Extension API(extension methods of object)
These api makes standard api to fluent sytnax
AssertAreEqual(actual, expected) -> actual.Is(expected).

  • Is
  • IsCollection
  • IsNot
  • IsNotCollection
  • IsEmpty
  • IsNull
  • IsNotNull
  • IsTrue
  • IsFalse
  • IsSampeReferenceAs
  • IsNotSampeReferenceAs
  • IsInstanceOf
  • IsNotInstanceOf

These API is port of neuecc/ChainingAssertion

with UniRx

UniRx helps Unit test easily. event as IObservable<T>, ObserveOnEveryValueChanged, ObservableTriggers can watch test target's state from outer environment.

public IEnumerator WithUniRxTestA()
{
    // subscribe event callback
    var subscription = obj.SomeEventAsObservable().First().ToYieldInstruction();

    // raise event 
    obj.RaiseEventSomething();

    // check event raise complete
    yield return subscription;

    subscription.Result.Is();
}

public IEnumerator UniRxTestB()
{
    // monitor value changed
    var subscription = obj.ObserveEveryValueChanged(x => x.someValue).Skip(1).First().ToYieldInstruction();

    // do something
    obj.DoSomething();

    // wait complete
    yield return subscription;

    subscription.Result.Is();
}

Author Info

Yoshifumi Kawai(a.k.a. neuecc) is a software developer in Japan.
He is the Director/CTO at Grani, Inc.
He is awarding Microsoft MVP for Visual C# since 2011.
He is known as the creator of UniRx(Reactive Extensions for Unity)

Blog: https://medium.com/@neuecc (English)
Blog: http://neue.cc/ (Japanese)
Twitter: https://twitter.com/neuecc (Japanese)

License

This library is under the MIT License.

runtimeunittesttoolkit's People

Contributors

neuecc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.