Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae200af

Browse files
authoredNov 2, 2023
Fix NUnit tests by migrating to use Unity Test Frameworks. (#646)
- Change NUnit tests to utilize Unity Test Frameworks - Add new script to enable dlls through Version Handler. This script should be removed before tests, or it will exit the Unity once Version Handler update is done. - Add required UPM packages for Unity Test Frameworks - Move all NUnit test code to the proper folders and add proper .asmdef, instead of using .csproj
1 parent 7782c4c commit ae200af

File tree

35 files changed

+254
-360
lines changed

35 files changed

+254
-360
lines changed
 

‎.github/workflows/test.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,10 @@ jobs:
132132
shell: bash
133133
timeout-minutes: 60
134134
run: |
135-
# DISABLE: NUnit test is currently broken from Unity 2019
136135
./gradlew test -q \
137136
-PINTERACTIVE_MODE_TESTS_ENABLED=0 \
138137
-PINCLUDE_TEST_TYPES="${{ needs.check_and_prepare.outputs.include_test_types }}" \
139-
-PEXCLUDE_TEST_TYPES="NUnit,${{ needs.check_and_prepare.outputs.exclude_test_types }}" \
138+
-PEXCLUDE_TEST_TYPES="${{ needs.check_and_prepare.outputs.exclude_test_types }}" \
140139
-PINCLUDE_TEST_MODULES="${{ needs.check_and_prepare.outputs.include_test_modules }}" \
141140
-PEXCLUDE_TEST_MODULES="${{ needs.check_and_prepare.outputs.exclude_test_modules }}" \
142141
-PEXCLUDE_TESTS="${{ needs.check_and_prepare.outputs.exclude_tests }}"

‎build.gradle

Lines changed: 125 additions & 169 deletions
Large diffs are not rendered by default.

‎source/AndroidResolver/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@
5757
[assembly: InternalsVisibleTo("Google.IOSResolver")]
5858
// Uses all classes for testing.
5959
[assembly: InternalsVisibleTo("Google.AndroidResolverIntegrationTests")]
60+
[assembly: InternalsVisibleTo("Google.AndroidResolverTests")]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Google.AndroidResolverTests",
3+
"references": [
4+
"UnityEngine.TestRunner",
5+
"UnityEditor.TestRunner"
6+
],
7+
"includePlatforms": [
8+
"Editor"
9+
],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": true,
13+
"precompiledReferences": [
14+
"nunit.framework.dll",
15+
"Google.VersionHandler.dll",
16+
"Google.VersionHandlerImpl.dll",
17+
"Google.JarResolver.dll"
18+
],
19+
"autoReferenced": false,
20+
"defineConstraints": [
21+
"UNITY_INCLUDE_TESTS"
22+
],
23+
"versionDefines": [],
24+
"noEngineReferences": false
25+
}

‎source/JarResolverTests/JarResolverTests.csproj

Lines changed: 0 additions & 75 deletions
This file was deleted.

‎source/JarResolverTests/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Google.PackageManagerResolverTests",
3+
"references": [
4+
"UnityEngine.TestRunner",
5+
"UnityEditor.TestRunner"
6+
],
7+
"includePlatforms": [
8+
"Editor"
9+
],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": true,
13+
"precompiledReferences": [
14+
"nunit.framework.dll",
15+
"Google.VersionHandler.dll",
16+
"Google.VersionHandlerImpl.dll",
17+
"Google.PackageManagerResolver.dll"
18+
],
19+
"autoReferenced": false,
20+
"defineConstraints": [
21+
"UNITY_INCLUDE_TESTS"
22+
],
23+
"versionDefines": [],
24+
"noEngineReferences": false
25+
}

‎source/PackageManagerResolver/unit_tests/PackageManagerResolverTests.csproj

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "Google.VersionHandlerImplTests",
3+
"references": [
4+
"UnityEngine.TestRunner",
5+
"UnityEditor.TestRunner"
6+
],
7+
"includePlatforms": [
8+
"Editor"
9+
],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": true,
13+
"precompiledReferences": [
14+
"nunit.framework.dll",
15+
"Google.VersionHandler.dll",
16+
"Google.VersionHandlerImpl.dll"
17+
],
18+
"autoReferenced": false,
19+
"defineConstraints": [
20+
"UNITY_INCLUDE_TESTS"
21+
],
22+
"versionDefines": [],
23+
"noEngineReferences": false
24+
}

‎source/VersionHandlerImpl/unit_tests/VersionHandlerImplTests.csproj

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"com.unity.test-framework": "1.1.33"
4+
}
5+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// <copyright file="TestResolverBootstrapped.cs" company="Google Inc.">
2+
// Copyright (C) 2023 Google Inc. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
// </copyright>
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Collections;
20+
using System.IO;
21+
22+
/// <summary>
23+
/// Run Version Handler to ensure all the libraries are properly enabled.
24+
/// </summary>
25+
[UnityEditor.InitializeOnLoad]
26+
public class VersionHandlerUpdater {
27+
/// <summary>
28+
/// Register a method to call when the Version Handler has enabled all plugins in the project.
29+
/// </summary>
30+
static VersionHandlerUpdater() {
31+
// Disable stack traces for more condensed logs.
32+
UnityEngine.Application.stackTraceLogType = UnityEngine.StackTraceLogType.None;
33+
UnityEngine.Debug.Log("Set up callback on Version Handler completion.");
34+
Google.VersionHandler.UpdateCompleteMethods = new [] {
35+
":VersionHandlerUpdater:VersionHandlerReady"
36+
};
37+
UnityEngine.Debug.Log("Enable plugin using the Version Handler.");
38+
Google.VersionHandler.UpdateNow();
39+
}
40+
41+
/// <summary>
42+
/// Called when the Version Handler has enabled all managed plugins in a project.
43+
/// </summary>
44+
public static void VersionHandlerReady() {
45+
UnityEngine.Debug.Log("The plugin should now be enabled by the Version Handler.");
46+
UnityEditor.EditorApplication.Exit(0);
47+
}
48+
}

0 commit comments

Comments
 (0)
Please sign in to comment.