Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 1e927f7

Browse files
committed
Added an app project for running tests
We want to start tracking specific cases where we identify issues and try to build some tests around them to avoid future regressions. This android app will serve as a solution that can be run to perform these tests. Currently it will need to be run manually.
1 parent c292790 commit 1e927f7

File tree

16 files changed

+552
-0
lines changed

16 files changed

+552
-0
lines changed

tests/AndroidSupport.Tests.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndroidSupport.Tests", "AndroidSupport.Tests\AndroidSupport.Tests.csproj", "{0BE8A946-F780-48E0-9DFC-6B0BD32B1A67}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{0BE8A946-F780-48E0-9DFC-6B0BD32B1A67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{0BE8A946-F780-48E0-9DFC-6B0BD32B1A67}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{0BE8A946-F780-48E0-9DFC-6B0BD32B1A67}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{0BE8A946-F780-48E0-9DFC-6B0BD32B1A67}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
EndGlobal
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props" Condition="Exists('..\..\packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{0BE8A946-F780-48E0-9DFC-6B0BD32B1A67}</ProjectGuid>
8+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>AndroidSupport.Tests</RootNamespace>
11+
<AssemblyName>AndroidSupport.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
13+
<AndroidApplication>True</AndroidApplication>
14+
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
15+
<AndroidResgenClass>Resource</AndroidResgenClass>
16+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
17+
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
18+
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
19+
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
20+
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23+
<DebugSymbols>true</DebugSymbols>
24+
<DebugType>full</DebugType>
25+
<Optimize>false</Optimize>
26+
<OutputPath>bin\Debug</OutputPath>
27+
<DefineConstants>DEBUG;</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
<AndroidLinkMode>None</AndroidLinkMode>
31+
<AndroidSupportedAbis>arm64-v8a;armeabi;armeabi-v7a;x86</AndroidSupportedAbis>
32+
</PropertyGroup>
33+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
34+
<DebugSymbols>true</DebugSymbols>
35+
<DebugType>pdbonly</DebugType>
36+
<Optimize>true</Optimize>
37+
<OutputPath>bin\Release</OutputPath>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
<AndroidManagedSymbols>true</AndroidManagedSymbols>
41+
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="System" />
45+
<Reference Include="System.Xml" />
46+
<Reference Include="System.Core" />
47+
<Reference Include="System.IO.Compression" />
48+
<Reference Include="System.Net.Http" />
49+
<Reference Include="xunit.abstractions">
50+
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\netstandard1.0\xunit.abstractions.dll</HintPath>
51+
</Reference>
52+
<Reference Include="xunit.assert">
53+
<HintPath>..\..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
54+
</Reference>
55+
<Reference Include="xunit.core">
56+
<HintPath>..\..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
57+
</Reference>
58+
<Reference Include="xunit.execution.dotnet">
59+
<HintPath>..\..\packages\xunit.extensibility.execution.2.2.0\lib\netstandard1.1\xunit.execution.dotnet.dll</HintPath>
60+
</Reference>
61+
<Reference Include="xunit.runner.utility.netstandard15">
62+
<HintPath>..\..\packages\xunit.runner.utility.2.2.0\lib\netstandard1.5\xunit.runner.utility.netstandard15.dll</HintPath>
63+
</Reference>
64+
<Reference Include="Xamarin.Android.Support.Animated.Vector.Drawable">
65+
<HintPath>..\..\output\Xamarin.Android.Support.Animated.Vector.Drawable.dll</HintPath>
66+
</Reference>
67+
<Reference Include="Xamarin.Android.Support.Annotations">
68+
<HintPath>..\..\output\Xamarin.Android.Support.Annotations.dll</HintPath>
69+
</Reference>
70+
<Reference Include="Xamarin.Android.Support.Compat">
71+
<HintPath>..\..\output\Xamarin.Android.Support.Compat.dll</HintPath>
72+
</Reference>
73+
<Reference Include="Xamarin.Android.Support.Core.UI">
74+
<HintPath>..\..\output\Xamarin.Android.Support.Core.UI.dll</HintPath>
75+
</Reference>
76+
<Reference Include="Xamarin.Android.Support.Core.Utils">
77+
<HintPath>..\..\output\Xamarin.Android.Support.Core.Utils.dll</HintPath>
78+
</Reference>
79+
<Reference Include="Xamarin.Android.Support.CustomTabs">
80+
<HintPath>..\..\output\Xamarin.Android.Support.CustomTabs.dll</HintPath>
81+
</Reference>
82+
<Reference Include="Xamarin.Android.Support.Design">
83+
<HintPath>..\..\output\Xamarin.Android.Support.Design.dll</HintPath>
84+
</Reference>
85+
<Reference Include="Xamarin.Android.Support.Dynamic.Animation">
86+
<HintPath>..\..\output\Xamarin.Android.Support.Dynamic.Animation.dll</HintPath>
87+
</Reference>
88+
<Reference Include="Xamarin.Android.Support.Exif">
89+
<HintPath>..\..\output\Xamarin.Android.Support.Exif.dll</HintPath>
90+
</Reference>
91+
<Reference Include="Xamarin.Android.Support.Fragment">
92+
<HintPath>..\..\output\Xamarin.Android.Support.Fragment.dll</HintPath>
93+
</Reference>
94+
<Reference Include="Xamarin.Android.Support.Media.Compat">
95+
<HintPath>..\..\output\Xamarin.Android.Support.Media.Compat.dll</HintPath>
96+
</Reference>
97+
<Reference Include="Xamarin.Android.Support.Percent">
98+
<HintPath>..\..\output\Xamarin.Android.Support.Percent.dll</HintPath>
99+
</Reference>
100+
<Reference Include="Xamarin.Android.Support.Recommendation">
101+
<HintPath>..\..\output\Xamarin.Android.Support.Recommendation.dll</HintPath>
102+
</Reference>
103+
<Reference Include="Xamarin.Android.Support.Transition">
104+
<HintPath>..\..\output\Xamarin.Android.Support.Transition.dll</HintPath>
105+
</Reference>
106+
<Reference Include="Xamarin.Android.Support.v4">
107+
<HintPath>..\..\output\Xamarin.Android.Support.v4.dll</HintPath>
108+
</Reference>
109+
<Reference Include="Xamarin.Android.Support.v7.AppCompat">
110+
<HintPath>..\..\output\Xamarin.Android.Support.v7.AppCompat.dll</HintPath>
111+
</Reference>
112+
<Reference Include="Xamarin.Android.Support.v7.CardView">
113+
<HintPath>..\..\output\Xamarin.Android.Support.v7.CardView.dll</HintPath>
114+
</Reference>
115+
<Reference Include="Xamarin.Android.Support.v7.GridLayout">
116+
<HintPath>..\..\output\Xamarin.Android.Support.v7.GridLayout.dll</HintPath>
117+
</Reference>
118+
<Reference Include="Xamarin.Android.Support.v7.MediaRouter">
119+
<HintPath>..\..\output\Xamarin.Android.Support.v7.MediaRouter.dll</HintPath>
120+
</Reference>
121+
<Reference Include="Xamarin.Android.Support.v7.Palette">
122+
<HintPath>..\..\output\Xamarin.Android.Support.v7.Palette.dll</HintPath>
123+
</Reference>
124+
<Reference Include="Xamarin.Android.Support.v7.Preference">
125+
<HintPath>..\..\output\Xamarin.Android.Support.v7.Preference.dll</HintPath>
126+
</Reference>
127+
<Reference Include="Xamarin.Android.Support.v7.RecyclerView">
128+
<HintPath>..\..\output\Xamarin.Android.Support.v7.RecyclerView.dll</HintPath>
129+
</Reference>
130+
<Reference Include="Xamarin.Android.Support.v8.RenderScript">
131+
<HintPath>..\..\output\Xamarin.Android.Support.v8.RenderScript.dll</HintPath>
132+
</Reference>
133+
<Reference Include="Xamarin.Android.Support.v13">
134+
<HintPath>..\..\output\Xamarin.Android.Support.v13.dll</HintPath>
135+
</Reference>
136+
<Reference Include="Xamarin.Android.Support.v14.Preference">
137+
<HintPath>..\..\output\Xamarin.Android.Support.v14.Preference.dll</HintPath>
138+
</Reference>
139+
<Reference Include="Xamarin.Android.Support.v17.Leanback">
140+
<HintPath>..\..\output\Xamarin.Android.Support.v17.Leanback.dll</HintPath>
141+
</Reference>
142+
<Reference Include="Xamarin.Android.Support.v17.Preference.Leanback">
143+
<HintPath>..\..\output\Xamarin.Android.Support.v17.Preference.Leanback.dll</HintPath>
144+
</Reference>
145+
<Reference Include="Xamarin.Android.Support.Vector.Drawable">
146+
<HintPath>..\..\output\Xamarin.Android.Support.Vector.Drawable.dll</HintPath>
147+
</Reference>
148+
<Reference Include="Mono.Android" />
149+
</ItemGroup>
150+
<ItemGroup>
151+
<Compile Include="MainActivity.cs" />
152+
<Compile Include="Resources\Resource.designer.cs" />
153+
<Compile Include="Properties\AssemblyInfo.cs" />
154+
<Compile Include="Tests.cs" />
155+
</ItemGroup>
156+
<ItemGroup>
157+
<None Include="Resources\AboutResources.txt" />
158+
<None Include="Properties\AndroidManifest.xml" />
159+
<None Include="Assets\AboutAssets.txt" />
160+
<None Include="packages.config" />
161+
</ItemGroup>
162+
<ItemGroup>
163+
<AndroidResource Include="Resources\layout\Main.axml" />
164+
<AndroidResource Include="Resources\values\Strings.xml" />
165+
<AndroidResource Include="Resources\mipmap-hdpi\Icon.png" />
166+
<AndroidResource Include="Resources\mipmap-mdpi\Icon.png" />
167+
<AndroidResource Include="Resources\mipmap-xhdpi\Icon.png" />
168+
<AndroidResource Include="Resources\mipmap-xxhdpi\Icon.png" />
169+
<AndroidResource Include="Resources\mipmap-xxxhdpi\Icon.png" />
170+
</ItemGroup>
171+
<ItemGroup>
172+
<Folder Include="Resources\drawable\" />
173+
</ItemGroup>
174+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
175+
<Import Project="..\..\generated.targets" />
176+
<Import Project="..\..\packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.targets" Condition="Exists('..\..\packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.targets')" />
177+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using Android.App;
2+
using Android.Widget;
3+
using Android.OS;
4+
using System.Collections.Generic;
5+
using System.Reflection;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
using System;
9+
using Xunit.Runners;
10+
using System.Threading.Tasks;
11+
using Android.Support.V7.App;
12+
using Android.Views;
13+
14+
namespace AndroidSupport.Tests
15+
{
16+
[Activity(Label = "AndroidSupport.Tests", MainLauncher = true, Theme="@style/Theme.AppCompat.Light", Icon = "@mipmap/icon")]
17+
public class MainActivity : AppCompatActivity
18+
{
19+
public static Activity TestParentActivity { get; set; }
20+
21+
22+
TaskCompletionSource<bool> tcsTests = new TaskCompletionSource<bool>();
23+
24+
AssemblyRunner assemblyRunner;
25+
26+
TestResultsAdapter adapter;
27+
ListView listView;
28+
29+
protected override void OnCreate(Bundle savedInstanceState)
30+
{
31+
base.OnCreate(savedInstanceState);
32+
33+
TestParentActivity = this;
34+
35+
// Set our view from the "main" layout resource
36+
SetContentView(Resource.Layout.Main);
37+
38+
listView = FindViewById<ListView>(Resource.Id.listView);
39+
40+
adapter = new TestResultsAdapter { Parent = this };
41+
listView.Adapter = adapter;
42+
43+
assemblyRunner = AssemblyRunner.WithoutAppDomain(Assembly.GetExecutingAssembly().GetName().Name + ".dll");
44+
assemblyRunner.OnDiscoveryComplete = DiscoveryCompleteHandler;;
45+
assemblyRunner.OnExecutionComplete = ExecutionCompleteHandler;;
46+
assemblyRunner.OnTestFailed = TestFailedHandler;;
47+
assemblyRunner.OnTestSkipped = TestSkippedHandler;
48+
assemblyRunner.OnTestPassed = TestPassedHandler;
49+
assemblyRunner.OnTestOutput = TestOutputHandler;
50+
51+
Console.WriteLine("Discovering...");
52+
assemblyRunner.Start ();
53+
}
54+
55+
bool anyFailed = false;
56+
57+
void DiscoveryCompleteHandler(DiscoveryCompleteInfo obj)
58+
{
59+
Console.WriteLine("Discovery Complete.");
60+
}
61+
62+
void ExecutionCompleteHandler(ExecutionCompleteInfo obj)
63+
{
64+
Console.WriteLine("Test Complete: Success={0}", !anyFailed);
65+
tcsTests.TrySetResult(anyFailed);
66+
}
67+
68+
void TestFailedHandler(TestFailedInfo obj)
69+
{
70+
anyFailed = true;
71+
adapter.AddResult(new TestResultInfo
72+
{
73+
Passed = false,
74+
DisplayName = obj.TestDisplayName
75+
});
76+
}
77+
78+
void TestSkippedHandler(TestSkippedInfo obj)
79+
{
80+
81+
}
82+
83+
void TestOutputHandler(TestOutputInfo obj)
84+
{
85+
86+
}
87+
88+
void TestPassedHandler(TestPassedInfo obj)
89+
{
90+
adapter.AddResult(new TestResultInfo
91+
{
92+
Passed = true,
93+
DisplayName = obj.TestDisplayName
94+
});
95+
}
96+
}
97+
98+
class TestResultInfo
99+
{
100+
public bool Passed { get; set; }
101+
public string DisplayName { get; set; }
102+
}
103+
104+
class TestResultsAdapter : BaseAdapter<TestResultInfo>
105+
{
106+
public Activity Parent;
107+
List<TestResultInfo> results = new List<TestResultInfo>();
108+
109+
public void AddResult(TestResultInfo info)
110+
{
111+
results.Add(info);
112+
Parent.RunOnUiThread(() => NotifyDataSetChanged());
113+
}
114+
115+
public override TestResultInfo this[int position]
116+
{
117+
get { return results[position]; }
118+
}
119+
120+
public override int Count
121+
{
122+
get { return results.Count; }
123+
}
124+
125+
public override long GetItemId(int position)
126+
{
127+
return position;
128+
}
129+
130+
public override View GetView(int position, View convertView, ViewGroup parent)
131+
{
132+
var view = convertView ?? LayoutInflater.From(Parent).Inflate(Android.Resource.Layout.TwoLineListItem, parent, false);
133+
134+
var r = this[position];
135+
136+
view.FindViewById<TextView>(Android.Resource.Id.Text1).Text = r.DisplayName;
137+
view.FindViewById<TextView>(Android.Resource.Id.Text2).Text = r.Passed ? "Passed" : "Failed";
138+
view.FindViewById<TextView>(Android.Resource.Id.Text2).SetTextColor(r.Passed ? Android.Graphics.Color.Green : Android.Graphics.Color.Maroon);
139+
140+
return view;
141+
}
142+
}
143+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.xamarin.androidsupport_tests">
3+
<uses-sdk android:minSdkVersion="10" />
4+
<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name">
5+
</application>
6+
</manifest>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using Android.App;
4+
5+
// Information about this assembly is defined by the following attributes.
6+
// Change them to the values specific to your project.
7+
8+
[assembly: AssemblyTitle("AndroidSupport.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("")]
13+
[assembly: AssemblyCopyright("${AuthorCopyright}")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
18+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
19+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
20+
21+
[assembly: AssemblyVersion("1.0.0")]
22+
23+
// The following attributes are used to specify the signing key for the assembly,
24+
// if desired. See the Mono documentation for more information about signing.
25+
26+
//[assembly: AssemblyDelaySign(false)]
27+
//[assembly: AssemblyKeyFile("")]

0 commit comments

Comments
 (0)