Class rpycUnitTests | Python for Unity | 2.1.1-preview.1
docs.unity3d.com
    Show / Hide Table of Contents

    Class rpycUnitTests

    The following tests may seem a bit complicated, but since we need to test with other processes, this takes time and thus we need to implement waiting methods. We leverage the UnityTest attribute for our waits. Contrary to regular C#, we can nest yield return calls and get the "intuitive" behaviour.

    Inheritance
    Object
    rpycUnitTests
    Namespace: rpycTests
    Syntax
    public class rpycUnitTests

    Properties

    ClientContactFlag

    Declaration
    public static bool ClientContactFlag { get; set; }
    Property Value
    Type Description
    Boolean

    Methods

    AsyncClientToServerCall()

    Note: nUnit should support asynchronous tests, but since unity is on a custom version there is something that prevents it from playing nice. "Await" manually on it

    Declaration
    public IEnumerator AsyncClientToServerCall()
    Returns
    Type Description
    IEnumerator

    CallServiceWithoutClient()

    Calls a service but there's no client.

    Verify it makes a reasonable error.

    Declaration
    public void CallServiceWithoutClient()

    CoroutineClientToServerCall()

    Tests that we can:

    • spawn a client
    • call a service on it asynchronously and have it play well with a coroutine
    • have the client call into Unity to manipulate the scene (create and rename an object)
    Declaration
    public IEnumerator CoroutineClientToServerCall()
    Returns
    Type Description
    IEnumerator

    RestartServer(String)

    Stops the server, then restart it, and wait for client to reconnect.

    Declaration
    public IEnumerator RestartServer(string clientID = "")
    Parameters
    Type Name Description
    String clientID

    Client ID used to see if the reconnected client is the one we expect. Only used if the shouldReconnect parameter is true

    Returns
    Type Description
    IEnumerator

    SetUp()

    Declaration
    public void SetUp()

    StartAndStopServer()

    Tests that we can:

    • spawn a client
    • call a service on it and get a result
    • shut down the server inviting a reconnect
    • reopen the server
    • find the same client and have it return proof that it knows the server shut down
    Declaration
    public IEnumerator StartAndStopServer()
    Returns
    Type Description
    IEnumerator

    The and stop server.

    StartClient(String, String)

    Starts a client (and the server if needed). Use as an IEnumerable or a coroutine

    Declaration
    public IEnumerator StartClient(string clientID, string clientName = "com.unity.scripting.python.tests.rpyc")
    Parameters
    Type Name Description
    String clientID

    Client's second name. Specified by the caller

    String clientName
    Returns
    Type Description
    IEnumerator

    TearDown()

    Declaration
    public void TearDown()

    TestBaseClient()

    Declaration
    public IEnumerator TestBaseClient()
    Returns
    Type Description
    IEnumerator

    TestClientWithoutServices()

    Declaration
    public IEnumerator TestClientWithoutServices()
    Returns
    Type Description
    IEnumerator

    TestKillClient()

    Declaration
    public IEnumerator TestKillClient()
    Returns
    Type Description
    IEnumerator

    TestNewerClient()

    Declaration
    public IEnumerator TestNewerClient()
    Returns
    Type Description
    IEnumerator

    TestServedExposedFunctions()

    Declaration
    public IEnumerator TestServedExposedFunctions()
    Returns
    Type Description
    IEnumerator

    TestTimeout()

    Declaration
    public IEnumerator TestTimeout()
    Returns
    Type Description
    IEnumerator

    UT1449StopServerWhileClientIsBusy()

    Declaration
    public IEnumerator UT1449StopServerWhileClientIsBusy()
    Returns
    Type Description
    IEnumerator

    WaitForSecondsDuringUnityTest(Double, Func<Boolean>)

    Because UnityTests can only yield return null (or an IEnumerator yield returning null), we cannot use Unity's WaitForSeconds. Make our own version. If a condition function was given, if the condition never evaluated to True during the loop, raises a Assert.Fail

    Declaration
    public IEnumerator WaitForSecondsDuringUnityTest(double waitTime, Func<bool> condition = null)
    Parameters
    Type Name Description
    Double waitTime

    The interval of time to wait for, in seconds.

    Func<Boolean> condition

    A function returning a boolean. If the function returns true, exit early.

    Returns
    Type Description
    IEnumerator
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023