Skip to content

Commit 236e823

Browse files
committed
Add test source import related script and document.
This commit changes Unity test build to use PlayMode test of Unity player instead of hand-made test suite with source code import.
1 parent c79065d commit 236e823

6 files changed

Lines changed: 87 additions & 10 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/[Aa]ssets/
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Remove-Item ./Assets -Force -Recurse
2+
3+
if (!(Test-Path ./bin/Debug/MsgPack.dll))
4+
{
5+
Write-Error "Build MsgPack.UnitTest.Unity.Full.Desktop project with Debug configuration first."
6+
exit 1
7+
}
8+
9+
[string[]]$additionalDefines = ("#define AOT", "#define NET35")
10+
[xml]$csproj = Get-Content ./MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop.csproj
11+
foreach($c in $csproj.Project.ItemGroup.Compile)
12+
{
13+
if ($c.Include -eq $null)
14+
{
15+
continue
16+
}
17+
18+
if ($c.Link -ne $null)
19+
{
20+
$destination = "Assets/UnitTests/$($c.Link)"
21+
}
22+
else
23+
{
24+
$destination = "Assets/UnitTests/$($c.Include)"
25+
}
26+
27+
$destinationDirectory = [IO.Path]::GetDirectoryName($destination);
28+
if (!(Test-Path $destinationDirectory))
29+
{
30+
New-Item $destinationDirectory -ItemType Directory | Out-Null
31+
}
32+
33+
Copy-Item $c.Include $destination -Force
34+
35+
if ($destination.EndsWith(".cs"))
36+
{
37+
$code = [IO.File]::ReadAllLines($destination)
38+
[IO.File]::WriteAllLines($destination, "#define UNITY")
39+
[IO.File]::AppendAllLines($destination, $additionalDefines)
40+
41+
# Change "protected internal" to "protected" because Unity build drop is not "InternalsVisibleTo" target.
42+
if ($destination.Contains("gen35") -or $destination.Contains("AutoMessagePackSerializerTest.Types.cs") -or $destination.Contains("RegressionTests.cs") -or $destination.Contains("SerializationContextTest.cs"))
43+
{
44+
$appender = [IO.File]::AppendText($destination)
45+
46+
foreach($line in $code)
47+
{
48+
$appender.WriteLine($line.Replace("protected internal", "protected"))
49+
}
50+
51+
$appender.Flush()
52+
$appender.Dispose()
53+
}
54+
else
55+
{
56+
[IO.File]::AppendAllLines($destination, $code)
57+
}
58+
}
59+
}
60+
61+
New-Item ./Assets/Dll -ItemType Directory | Out-Null
62+
Copy-Item ./bin/Debug/MsgPack.dll ./Assets/Dll/MsgPack.dll -Force

test/MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop/MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,6 @@
791791
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
792792
</ItemGroup>
793793
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
794-
<PropertyGroup>
795-
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT'">RoboCopy $(ProjectDir)$(OutDir) $(ProjectDir)\..\MsgPack.UnitTest.Unity.Il2cpp.Full\Assets\Plugins\Dlls\ *.dll /MIR
796-
if %25ERRORLEVEL%25 geq 8 exit 1
797-
exit 0</PostBuildEvent>
798-
<PostBuildEvent Condition="'$(OS)' != 'Windows_NT'">rsync -a -r --delete $(ProjectDir)$(OutDir)/*.dll $(ProjectDir)/../MsgPack.UnitTest.Unity.Il2cpp.Full/Assets/Plugins/Dlls/</PostBuildEvent>
799-
</PropertyGroup>
800794
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
801795
Other similar extension points exist, see Microsoft.Common.targets.
802796
<Target Name="BeforeBuild">
Binary file not shown.
Binary file not shown.

test/MsgPack.UnitTest.Unity.Il2cpp.Full/Readme.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,31 @@ MessagePack for CLI Unit Test for Unity IL2CPP
44
Overview
55
---
66
This directory contains unit test framework for Unity IL2CPP backend.
7-
The idea of the framework borrowed from UniRx, and many codes are based on UniRx unit testing.
87

98
How to build
109
---
1110

12-
1. Open MsgPack.UnitTest.Unity.Il2cpp.Full.sln first (specifically, you need to build MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop project).
13-
2. Build all. Three dlls (MsgPack.dll, MsgPack.UnitTest.dll, nunitlite.dll) will be copied to Assets/Plugins/Dlls
14-
3. Open this directory in Unity Editor.
11+
1. Go to `../MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop` directory.
12+
2. Run `MakeAssets.ps1` PowerShell script (it may work on PowerShell Core)
13+
3. Ensure `../MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop/Assets` directory and its subtree have been generated.
14+
4. Open this folder with Unity.
15+
5. Import `../MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop/Assets/Dll` directory into `Assets` of Unity project with Unity Editor.
16+
6. Import `../MsgPack.UnitTest.Unity.Il2cpp.Full.Desktop/Assets/UnitTests` directory into `Assets` of Unity project with Unity Editor.
17+
18+
How to run
19+
---
20+
21+
See [Unity official document](https://docs.unity3d.com/Manual/testing-editortestsrunner.html) for details.
22+
23+
1. Select [[Window]] &gt; [[Unit Test Runner]]
24+
2. Click [[PlayMode]] tab.
25+
* If you see [[Enable playmode tests]] button, click it and then restart the Unity editor.
26+
3. Ensure one more unit tests are shown in the dialog.
27+
4. Click [[Run all]] to run in the Editor.
28+
5. Open [[Build Settings]] dialog, and select a platform you want to run tests.
29+
* Note that author only tests in iOS (AOT).
30+
6. Click [[Run all in player ({YourSelectedPlatform})]] button to run tests in play-mode.
31+
* If you face an error that the editor cannot find scene file, do following:
32+
1. Ensure that auto generated scene (its name should be "InitTestScene{RandomNumber}").
33+
2. In [[Build Settings]] dialog, click [[Add Open Scenes]] and check *only* above auto generated scene.
34+
3. Click [[Build and Run]] (or [[Build]] and then run the player built).

0 commit comments

Comments
 (0)