Skip to content

Commit

Permalink
Added tests for TestCloud and UITest aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Aug 21, 2015
1 parent 6772eea commit 71b11db
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cake.Xamarin.Tests/Cake.Xamarin.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="XamarinComponentTests.cs" />
<Compile Include="Fakes\FakeCakeContext.cs" />
<Compile Include="iOSTests.cs" />
<Compile Include="TestCloudTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Cake.Xamarin.Tests/Fakes/FakeCakeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public FakeCakeContext ()
var toolResolvers = new List<IToolResolver> ();
var registry = new WindowsRegistry ();

var nugetToolResolver = new Cake.Core.IO.NuGet.NuGetToolResolver (fileSystem, environment, globber);
toolResolvers.Add (nugetToolResolver);

context = new CakeContext (fileSystem, environment, globber, log, args, processRunner, toolResolvers, registry);
context.Environment.WorkingDirectory = testsDir;
}
Expand Down
2 changes: 1 addition & 1 deletion Cake.Xamarin.Tests/Fakes/FakeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public FakeLog()
/// <value>The verbosity.</value>
public Verbosity Verbosity
{
get { return Verbosity.Quiet; }
get { return Verbosity.Diagnostic; }
}

/// <summary>
Expand Down
104 changes: 104 additions & 0 deletions Cake.Xamarin.Tests/TestCloudTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using Cake.Xamarin.Tests.Fakes;
using NUnit.Framework;
using Cake.Common.IO;
using Cake.Common.Tools.NuGet;
using Cake.Common.Tools;
using System.Linq;
using Cake.Common.Text;

namespace Cake.Xamarin.Tests
{
[TestFixture, Category ("TestCloudTests")]
public class TestCloudTests
{
FakeCakeContext context;

[SetUp]
public void Setup ()
{
context = new FakeCakeContext ();

context.CakeContext.CleanDirectories ("./TestProjects/**/bin");
context.CakeContext.CleanDirectories ("./TestProjects/**/obj");
}

[TearDown]
public void Teardown ()
{
context.DumpLogs ();
}

[Test]
public void UITestsTest ()
{
context.CakeContext.NuGetRestore ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid.sln");

// Try and find a console runner from the installed nugets
var nunitConsolePath = context.CakeContext.GetFiles ("./TestProjects/HelloWorldAndroid/**/nunit-console.exe")
.FirstOrDefault ();

// Build the sln so the unit tests assembly gets built
context.CakeContext.DotNetBuild ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid.sln");

// Build the .apk to test
var apk = context.CakeContext.AndroidPackage ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid/HelloWorldAndroid.csproj");

// Copy to the expected location of the UITests
context.CakeContext.CopyFile (apk, "./TestProjects/HelloWorldAndroid/HelloWorldAndroid.UITests/bin/Debug/app.apk");

try {
// Run the uitests
context.CakeContext.UITest ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid.UITests/bin/Debug/HelloWorldAndroid.UITests.dll",
new Cake.Common.Tools.NUnit.NUnitSettings {
ToolPath = nunitConsolePath
});
} catch (Exception ex) {
Console.WriteLine (ex);
Console.WriteLine (context.GetLogs ());
Assert.Fail (context.GetLogs ());
}
}

[Test]
public void TestCloudTest ()
{
context.CakeContext.NuGetRestore ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid.sln");

// Try and find a test-cloud-exe from the installed nugets
var testCloudExePath = context.CakeContext.GetFiles ("./TestProjects/HelloWorldAndroid/**/test-cloud.exe")
.FirstOrDefault ();

// Build the sln so the unit tests assembly gets built
context.CakeContext.DotNetBuild ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid.sln");

// Build the .apk to test
var apk = context.CakeContext.AndroidPackage ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid/HelloWorldAndroid.csproj", true);

var xtcApiKey = context.CakeContext.TransformTextFile ("../xtc-api-key").ToString ();
var xtcEmail = context.CakeContext.TransformTextFile ("../xtc-email").ToString ();

try {
// Run testcloud
context.CakeContext.TestCloud (apk,
xtcApiKey,
"2b9b256d",
xtcEmail,
"./TestProjects/HelloWorldAndroid/HelloWorldAndroid.UITests/bin/Debug/",
new TestCloudSettings {
ToolPath = testCloudExePath
});

context.CakeContext.UITest ("./TestProjects/HelloWorldAndroid/HelloWorldAndroid.UITests/bin/Debug/HelloWorldAndroid.UITests.dll",
new Cake.Common.Tools.NUnit.NUnitSettings {
ToolPath = testCloudExePath
});
} catch (Exception ex) {
Console.WriteLine (ex);
Console.WriteLine (context.GetLogs ());
Assert.Fail (context.GetLogs ());
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.4" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ProjectGuid>{F6F203A0-84ED-4E80-A797-AFB8C60ABD93}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>HelloWorld.UITests</RootNamespace>
<AssemblyName>HelloWorld.UITests</AssemblyName>
<AssemblyName>HelloWorldAndroid.UITests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -29,11 +29,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Xamarin.UITest">
<HintPath>..\packages\Xamarin.UITest.0.7.1\lib\Xamarin.UITest.dll</HintPath>
<HintPath>..\packages\Xamarin.UITest.1.0.0\lib\Xamarin.UITest.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public class Tests
[SetUp]
public void BeforeEachTest ()
{
app = ConfigureApp.Android.StartApp ();
app = ConfigureApp
.Android
.ApkFile ("app.apk")
.StartApp ();
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.3" targetFramework="net45" />
<package id="Xamarin.UITest" version="0.7.1" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnit.Runners" version="2.6.4" targetFramework="net45" />
<package id="Xamarin.UITest" version="1.0.0" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion Cake.Xamarin.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Cake.Xamarin</id>
<version>1.0.15</version>
<version>1.0.16</version>
<authors>Redth</authors>
<owners>Redth</owners>
<title>Cake.Xamarin</title>
Expand Down
2 changes: 1 addition & 1 deletion Cake.Xamarin/TestCloudRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Run (FilePath apkFile, string apiKey, string devicesHash, string use
builder.Append ("--assembly-dir");
builder.AppendQuoted (uitestAssemblies.MakeAbsolute (_cakeEnvironment).FullPath);

Run (settings, builder, settings.ToolPath);
Run (settings, builder, settings.ToolPath, new ProcessSettings { RedirectStandardOutput = true }, null);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions xtc-api-key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d0cf24c6c683dc634dfef19be22fee6b
1 change: 1 addition & 0 deletions xtc-email
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]

0 comments on commit 71b11db

Please sign in to comment.