• Stars
    star
    268
  • Rank 148,100 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created about 7 years ago
  • Updated 18 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CLI/GUI Frontend of Unity Test Runner to test on any platform.

RuntimeUnitTestToolkit(v2)

GitHub Actions Releases

RuntimeUnitTestToolkit is the supplement of Unity Test Runner. Unity Test Runner works fine but player runner(any target platform) is very poor. RuntimeUnitTestToolkit provides CLI(for run on CI) and GUI(for run on any platforms(Windows, Mac, iOS, Android, etc...)) frontend of Unity Test Runner.

You can write test that work on Unity Test Runner, it also can build runtime player by RuntimeUnitTestToolkit.

image

Choose the settings(ScriptBackend - Mono or IL2CPP, BuildTarget, CLI(Headless) or GUI) and select BuildUnitTest.

image

You can see the test result of CUI(Headless) player or

image

GUI player on your built platforms.

The test is same as listed on Unity Test Runner's PlayMode tests.

image

Target test allows asmdef's Test Assemblies so does not includes test files when standard build(but include when build by RuntimeUnitTestToolkit automatically).

On CI(use CLI(Headless) mode), if fail the test, shows red. You can notify to Slack or other communication tools by CI's integration.

image

You can also use GUI test on UnityEditor, choose LoadUnitTestScene and play.

image

Install

RuntimeUnitTestToolkit.*version*.unitypackage on releases page or package.json exists on RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit for package manager.

After Unity 2019.3.4f1, Unity 2020.1a21, that support path query parameter of git package. You can add https://github.com/Cysharp/RuntimeUnitTestToolkit.git?path=RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit to Package Manager UI.

Or add "com.cysharp.runtimeunittesttoolkit": "https://github.com/Cysharp/RuntimeUnitTestToolkit.git?path=RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit" to Packages/manifest.json.

If you want to set a target version, RuntimeUnitTestToolkit is using *.*.* release tag so you can specify a version like #2.3.0. For example https://github.com/Cysharp/RuntimeUnitTestToolkit.git?path=RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit#2.3.0.

CommandLine Reference

For example, this library's CI(GitHub Actions) itself.

# Execute scripts: RuntimeUnitTestToolkit(Linux64/Mono2x)
- name: Build UnitTest(Linux64, mono)
  run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
  working-directory: RuntimeUnitTestToolkit

# Execute player:
- name: Execute UnitTest
  run: ./RuntimeUnitTestToolkit/bin/UnitTest/StandaloneLinux64_Mono2x/test

You can invoke -executeMethod UnitTestBuilder.BuildUnitTest and some options.

Command Desc
/headless Boolean switch, build CLI mode. Default is false.
/scriptBackend ScriptingImplementation Enum string(Mono2x or IL2CPP or WinRTDotNET )
/buildTarget BuildTarget Enum string(StandaloneWindows64, StandaloneLinux64, StandaloneOSX, iOS, Android, etc...)
/buildPath FilePath String path. Default is bin/UnitTest/{BuildTarget}_{ScriptBackend}/test(If windows test.exe, Android test.apk, OSX test.app)

You can pass by / prefix.

Attribute

RuntimeUnitTestToolkit supports these attributes.

  • SetUp
  • TearDown
  • Test
  • UnityTest
  • TestCase
  • TestCaseSource
  • OneTimeSetUp
  • OneTimeTearDown
  • SetUpFixture
  • UnitySetUp
  • UnityTearDown

Async Test

Unity's [UnityTest], [UnitySetup], [UnityTearDown] attribute can test coroutine(IEnumerator) but can not test async. Cysharp/UniTask and UniTask.ToCoroutine bridges async/await to coroutine so you can test async method.

[UnityTest]
public IEnumerator DelayIgnore() => UniTask.ToCoroutine(async () =>
{
    var time = Time.realtimeSinceStartup;

    Time.timeScale = 0.5f;
    try
    {
        await UniTask.Delay(TimeSpan.FromSeconds(3), ignoreTimeScale: true);

        var elapsed = Time.realtimeSinceStartup - time;
        Assert.AreEqual(3, (int)Math.Round(TimeSpan.FromSeconds(elapsed).TotalSeconds, MidpointRounding.ToEven));
    }
    finally
    {
        Time.timeScale = 1.0f;
    }
});

Advanced

How to get stdout/stderr & ExitCode with StandaloneOSX w/Headless

/headless argument offer CUI player, therefore user can handle stdout/stderr and ExitCode on CI.

However you will find it's not for StandaloneOSX. BuildUnitTest on StandaloneOSX generate .app but you cannot get any output or ExitCode with open -a xxxx.app Let's see what going on with this repository's UnitTest.

$ cd ./RuntimeUnitTestToolkit
$ /Applications/Unity/Hub/Editor/2018.3.9f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneOSX
# nothind will output
$ open -a ./bin/UnitTest/StandaloneOSX_Mono2x/test.app
# always exitcode is 0, even if test failed.
$ echo $?
0

Trick

You can obtain stdout/stderr and ExitCode by executing actual binary inside xxxx.app.

binary path is always xxxx.app/Contents/MacOS/YOUR_APP_NAME in StandaloneOSX.

Try open terminal and call binary, then you will find expected output.

$ ./bin/UnitTest/StandaloneOSX_Mono2x/test.app/Contents/MacOS/RuntimeUnitTestToolkit

image

You can Pipe as usual. ExitCode will be 0 when test success, and 1 for failed.

$ ./test.app/Contents/MacOS/RuntimeUnitTestToolkit | grep OK
[OK]SumTest, 14.30ms
[OK]AsyncTest, 1039.78ms

image

image

License

This library is under the MIT License.

More Repositories

1

UniTask

Provides an efficient allocation free async/await integration for Unity.
C#
7,314
star
2

MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
C#
3,611
star
3

MemoryPack

Zero encoding extreme performance binary serializer for C# and Unity.
C#
2,807
star
4

ZString

Zero Allocation StringBuilder for .NET and Unity.
C#
1,860
star
5

MasterMemory

Embedded Typed Readonly In-Memory Document Database for .NET and Unity.
C#
1,410
star
6

R3

The new future of dotnet/reactive and UniRx.
C#
1,332
star
7

MessagePipe

High performance in-memory/distributed messaging pipeline for .NET and Unity.
C#
1,258
star
8

ConsoleAppFramework

Micro-framework for console applications to building CLI tools/Daemon/Batch for .NET, C#.
C#
1,201
star
9

ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
C#
1,081
star
10

Ulid

Fast .NET C# Implementation of ULID for .NET and Unity.
C#
831
star
11

SimdLinq

Drop-in replacement of LINQ aggregation operations extremely faster with SIMD.
C#
726
star
12

csbindgen

Generate C# FFI from Rust for automatically brings native code and C native library to .NET and Unity.
Rust
558
star
13

ObservableCollections

High performance observable collections and synchronized views, for WPF, Blazor, Unity.
C#
419
star
14

ProcessX

Simplify call an external process with the async streams in C# 8.0.
C#
410
star
15

UnitGenerator

C# Source Generator to create value-object, inspired by units of measure.
C#
309
star
16

YetAnotherHttpHandler

YetAnotherHttpHandler brings the power of HTTP/2 (and gRPC) to Unity and .NET Standard.
C#
290
star
17

AlterNats

An alternative high performance NATS client for .NET.
C#
279
star
18

NativeMemoryArray

Utilized native-memory backed array for .NET and Unity - over the 2GB limitation and support the modern API(IBufferWriter, ReadOnlySequence, scatter/gather I/O, etc...).
C#
246
star
19

PrivateProxy

Source Generator and .NET 8 UnsafeAccessor based high-performance strongly-typed private accessor for unit testing and runtime.
C#
234
star
20

StructureOfArraysGenerator

Structure of arrays source generator to make CPU Cache and SIMD friendly data structure for high-performance code in .NET and Unity.
C#
229
star
21

MagicPhysX

.NET PhysX 5 binding to all platforms(win, osx, linux) for 3D engine, deep learning, dedicated server of gaming.
Rust
221
star
22

LogicLooper

A library for building server application using loop-action programming model on .NET.
C#
211
star
23

DFrame

Distributed load testing framework for .NET and Unity.
C#
206
star
24

Utf8StreamReader

Utf8 based StreamReader for high performance text processing.
C#
194
star
25

LitJWT

Lightweight, Fast JWT(JSON Web Token) implementation for .NET.
C#
190
star
26

KcpTransport

KcpTransport is a Pure C# implementation of RUDP for high-performance real-time network communication
C#
183
star
27

Utf8StringInterpolation

Successor of ZString; UTF8 based zero allocation high-peformance String Interpolation and StringBuilder.
C#
140
star
28

CsprojModifier

CsprojModifier performs additional processing when Unity Editor generates the .csproj.
C#
135
star
29

ValueTaskSupplement

Append supplemental methods(WhenAny, WhenAll, Lazy) to ValueTask.
C#
126
star
30

Kokuban

Simplifies styling strings in the terminal for .NET application.
C#
121
star
31

Claudia

Unofficial Anthropic Claude API client for .NET.
C#
118
star
32

SlnMerge

SlnMerge merges the solution files when generating solution file by Unity Editor.
C#
111
star
33

GrpcWebSocketBridge

Yet Another gRPC over HTTP/1 using WebSocket implementation, primarily targets .NET platform.
C#
71
star
34

WebSerializer

Convert Object into QueryString/FormUrlEncodedContent for C# HttpClient REST Request.
C#
60
star
35

RandomFixtureKit

Fill random/edge-case value to target type for unit testing, supports both .NET Standard and Unity.
C#
43
star
36

Actions

30
star
37

DocfxTemplate

Patchworked DocFX v2 template for Cysharp
JavaScript
6
star
38

com.unity.ide.visualstudio-backport

Backport of com.unity.ide.visualstudio to before Unity 2019.4.21
C#
1
star