Skip to content

Commit 5eeb349

Browse files
author
Stewart Miles
committed
Refactored Android Resolver integration test.
* Migrated common test framework code from the Android Resolver's integration test to the shared IntegrationTester. * Moved the Android Resolver integration test into a DLL so that it's possible to compile the project ahead of time and remove all of the brittle usage of reflection. Bug: 150471207 Change-Id: Ib698c3bbf312e2b197a3c30b042fb3250d556af0
1 parent d9db158 commit 5eeb349

File tree

198 files changed

+273
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+273
-418
lines changed

build.gradle

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ Task createXbuildTask(String taskName, String taskDescription,
692692
sprintf("/property:OutputPath=%s%s",
693693
binaryOutputDir.absolutePath,
694694
File.separator),
695+
"/verbosity:quiet",
695696
projectToBuild.absolutePath])
696697
}
697698
task.ext.buildDir = outputDir
@@ -1017,13 +1018,16 @@ Task createSetupUnityProjectTask(String taskName, Iterable<Task> dependsOn,
10171018
* @param additionalArguments Additional arguments to pass to Unity when
10181019
* executing the test.
10191020
* @param batchMode Whether to execute Unity in batch mode.
1021+
* @param editorAssets Files to copy into the Assets/Editor folder in the
1022+
* project.
10201023
* @param createTaskClosure Optional task used to start Unity, this must
10211024
* conform to tasks.create(name, description, type, dependsOn).
10221025
*
10231026
* @returns Test task.
10241027
*/
10251028
Task createUnityTestTask(String taskName, String description,
10261029
Iterable<Task> dependsOn, File testScriptsDir,
1030+
Iterable<File> editorAssets,
10271031
Iterable<String> additionalArguments,
10281032
Boolean batchMode, createTaskClosure) {
10291033
List<File> inputFiles = fileTree(testScriptsDir).collect {
@@ -1043,8 +1047,22 @@ Task createUnityTestTask(String taskName, String description,
10431047
inputFiles, testScriptsDir, setupTestProject.ext.projectDir,
10441048
[setupTestProject], null)
10451049

1050+
// Task which copies editor scripts into the project.
1051+
Task copyEditorAssets = tasks.create(
1052+
name: sprintf("copyEditorAssetsFor%s", taskName),
1053+
description: sprintf("Copy the editor assets into the %s Unity project.",
1054+
taskName),
1055+
type: Copy,
1056+
dependsOn: [setupTestProject])
1057+
copyEditorAssets.with {
1058+
from editorAssets
1059+
into new File(new File(setupTestProject.ext.projectDir, "Assets"),
1060+
"Editor")
1061+
}
1062+
10461063
// Create the test task.
1047-
Task testTask = createUnityTask(taskName, "test", [copyTestScripts],
1064+
Task testTask = createUnityTask(taskName, "test",
1065+
[copyTestScripts, copyEditorAssets],
10481066
setupTestProject.ext.projectDir.name,
10491067
setupTestProject.ext.containerDir,
10501068
additionalArguments, batchMode,
@@ -1070,6 +1088,8 @@ Task createUnityTestTask(String taskName, String description,
10701088
* @param dependsOn Dependencies of the new task.
10711089
* @param testScriptsDir Directory containing scripts to copy into the test
10721090
* project and execute for testing.
1091+
* @param editorAssets Files to copy into the Assets/Editor folder in the
1092+
* project.
10731093
* @param additionalArguments Additional arguments to pass to Unity.
10741094
* @param createTaskClosure Optional task used to start Unity, this must
10751095
* conform to tasks.create(name, description, type, dependsOn).
@@ -1079,6 +1099,7 @@ Task createUnityTestTask(String taskName, String description,
10791099
Task createUnityTestBatchAndNonBatch(String taskName, String description,
10801100
Iterable<Task> dependsOn,
10811101
File testScriptsDir,
1102+
Iterable<File> editorAssets,
10821103
Iterable<String> additionalArguments,
10831104
createTaskClosure) {
10841105
return tasks.create(name: taskName,
@@ -1087,13 +1108,13 @@ Task createUnityTestBatchAndNonBatch(String taskName, String description,
10871108
createUnityTestTask(
10881109
sprintf("%sBatchMode", taskName),
10891110
sprintf("%s (Batch Mode)", description),
1090-
dependsOn, testScriptsDir, additionalArguments, true,
1091-
createTaskClosure),
1111+
dependsOn, testScriptsDir, editorAssets,
1112+
additionalArguments, true, createTaskClosure),
10921113
createUnityTestTask(
10931114
sprintf("%sInteractiveMode", taskName),
10941115
sprintf("%s (Interactive Mode)", description),
1095-
dependsOn, testScriptsDir, additionalArguments, false,
1096-
createTaskClosure)])
1116+
dependsOn, testScriptsDir, editorAssets,
1117+
additionalArguments, false, createTaskClosure)])
10971118
}
10981119

10991120
Task compileResolverLibTests = createXbuildTask(
@@ -1649,15 +1670,19 @@ createUnityTestBatchAndNonBatch(
16491670
("Imports the plugin into a Unity project and verifies all " +
16501671
"components can be activated by the Version Handler."),
16511672
[buildPlugin],
1652-
new File(project.ext.scriptDirectory,"source/VersionHandlerImpl/test/activation"), [], null)
1673+
new File(project.ext.scriptDirectory,
1674+
"source/VersionHandlerImpl/test/activation"),
1675+
[], [], null)
16531676

16541677
// Launch the test via a script that runs a local web server.
16551678
createUnityTestBatchAndNonBatch(
16561679
"testVersionHandlerWebRequest",
16571680
("Imports the plugin into a Unity project tests the PortableWebRequest " +
16581681
"class."),
16591682
[buildPlugin],
1660-
new File(project.ext.scriptDirectory, "source/VersionHandlerImpl/test/webrequest"), [],
1683+
new File(project.ext.scriptDirectory,
1684+
"source/VersionHandlerImpl/test/webrequest"),
1685+
[], [],
16611686
{ String name, String description, Iterable<Task> depends,
16621687
File executable, Iterable<String> args ->
16631688
Iterable<String> runnerArgs = [executable.absolutePath] + args
@@ -1678,7 +1703,11 @@ createUnityTestBatchAndNonBatch(
16781703
("Imports the plugin into a Unity project and tests reflection " +
16791704
"methods."),
16801705
[buildPlugin],
1681-
new File(project.ext.scriptDirectory, "source/VersionHandler/test/reflection"), [], null)
1706+
new File(project.ext.scriptDirectory,
1707+
"source/VersionHandler/test/reflection"),
1708+
[],
1709+
[],
1710+
null)
16821711

16831712
Task compileIntegrationTester = createXbuildTask(
16841713
"compileIntegrationTester",
@@ -1692,14 +1721,66 @@ Task compileIntegrationTester = createXbuildTask(
16921721
new File("Google.IntegrationTester.dll.mdb")],
16931722
[compileVersionHandler])
16941723

1695-
createUnityTestBatchAndNonBatch(
1696-
"testAndroidResolverAsyncResolve",
1724+
/*
1725+
* Creates a task which compiles and run a Unity integration test.
1726+
*
1727+
* @param taskName Name of the test.
1728+
* @param description Description of the task.
1729+
* @param dependsOn Dependencies of the new task.
1730+
* @param integrationTestProject Project within
1731+
* project.ext.pluginSolutionFile that contains the integration test.
1732+
* @param integrationTestProjectSources Source files integrationTestProject
1733+
* requires.
1734+
* @param integrationTestProjectOutputs Assemblies generated by the
1735+
* integrationTestProject.
1736+
* @param unityProjectDir Directory containing a assets to copy into the
1737+
* integration test project.
1738+
* @param arguments Additional arguments for Unity when running the integration
1739+
* test.
1740+
*/
1741+
Task createUnityIntegrationTest(String taskName,
1742+
String description,
1743+
Iterable<Task> dependsOn,
1744+
String integrationTestProject,
1745+
Iterable<File> integrationTestProjectSources,
1746+
Iterable<File> integrationTestProjectOutputs,
1747+
File unityProjectDir,
1748+
Iterable<String> arguments) {
1749+
Task compileIntegrationTest = createXbuildTask(
1750+
sprintf("compile%s", integrationTestProject),
1751+
sprintf("Compile %s for %s", integrationTestProject, taskName),
1752+
project.ext.pluginSolutionFile,
1753+
integrationTestProject,
1754+
integrationTestProjectSources,
1755+
new File(project.ext.buildDir, integrationTestProject),
1756+
integrationTestProjectOutputs,
1757+
[compileIntegrationTester] + dependsOn)
1758+
1759+
createUnityTestBatchAndNonBatch(
1760+
taskName,
1761+
description,
1762+
[buildPlugin],
1763+
unityProjectDir,
1764+
compileIntegrationTest.outputs.files +
1765+
compileIntegrationTester.outputs.files,
1766+
arguments, null)
1767+
}
1768+
1769+
createUnityIntegrationTest(
1770+
"testAndroidResolverIntegrationTests",
16971771
("Imports the plugin into a Unity project, runs Android resolution with " +
16981772
"a combination of dependencies added via the programmatic API and via " +
16991773
"XML files, verifying all dependencies resolve successfully."),
1700-
[buildPlugin],
1701-
new File(project.ext.scriptDirectory, "source/AndroidResolver/test/resolve_async"),
1702-
["-buildTarget", "android"], null) // TODO: Move this into the test!?
1774+
[compileAndroidResolver],
1775+
"AndroidResolverIntegrationTests",
1776+
fileTree(new File(new File(project.ext.pluginSourceDir, "AndroidResolver"),
1777+
"test")),
1778+
[new File("Google.AndroidResolverIntegrationTests.dll"),
1779+
new File("Google.AndroidResolverIntegrationTests.dll.mdb")],
1780+
new File(
1781+
project.ext.scriptDirectory,
1782+
"source/AndroidResolver/test/AndroidResolverIntegrationTestsUnityProject"),
1783+
["-buildTarget", "android"])
17031784

17041785
task cleanTests(type: Delete) {
17051786
description "Clean test directories."

source/AndroidResolver/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@
5555

5656
// Uses XmlDependencies class.
5757
[assembly: InternalsVisibleTo("Google.IOSResolver")]
58-
58+
// Uses all classes for testing.
59+
[assembly: InternalsVisibleTo("Google.AndroidResolverIntegrationTests")]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{6CB19B5A-371A-5E50-A3F7-E24F1696D501}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>Google</RootNamespace>
11+
<AssemblyName>Google.AndroidResolverIntegrationTests</AssemblyName>
12+
<ReleaseVersion>1.2</ReleaseVersion>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>True</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>False</Optimize>
19+
<OutputPath>bin\Debug</OutputPath>
20+
<DefineConstants>DEBUG;UNITY_EDITOR</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
<ConsolePause>False</ConsolePause>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugSymbols>True</DebugSymbols>
27+
<DebugType>full</DebugType>
28+
<Optimize>True</Optimize>
29+
<OutputPath>bin\Release</OutputPath>
30+
<DefineConstants>DEBUG;UNITY_EDITOR</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<ConsolePause>False</ConsolePause>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<UnityHintPath>..\..\unity_dlls</UnityHintPath>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="UnityEditor">
40+
<HintPath>$(UnityHintPath)/UnityEditor.dll</HintPath>
41+
</Reference>
42+
<Reference Include="UnityEngine">
43+
<HintPath>$(UnityHintPath)/UnityEngine.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.Xml" />
48+
</ItemGroup>
49+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
50+
<ItemGroup>
51+
<Folder Include="src\" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<Compile Include="src\AndroidResolverIntegrationTests.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ProjectReference Include="..\..\VersionHandler\VersionHandler.csproj">
58+
<Project>{5378B37A-887E-49ED-A8AE-42FA843AA9DC}</Project>
59+
<Name>VersionHandler</Name>
60+
</ProjectReference>
61+
<ProjectReference Include="..\..\VersionHandlerImpl\VersionHandlerImpl.csproj">
62+
<Project>{1E162334-8EA2-440A-9B3A-13FD8FE5C22E}</Project>
63+
<Name>VersionHandlerImpl</Name>
64+
</ProjectReference>
65+
<ProjectReference Include="..\..\IntegrationTester\IntegrationTester.csproj">
66+
<Project>{DBD8D4D9-61AC-4E75-8CDC-CABE7033A040}</Project>
67+
<Name>IntegrationTester</Name>
68+
</ProjectReference>
69+
<ProjectReference Include="..\AndroidResolver.csproj">
70+
<Project>{82EEDFBE-AFE4-4DEF-99D9-BC929747DD9A}</Project>
71+
<Name>AndroidResolver</Name>
72+
</ProjectReference>
73+
</ItemGroup>
74+
</Project>

0 commit comments

Comments
 (0)