Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] First Pass at adding Unit tests for the MSBuild Tasks #26

Merged
merged 1 commit into from
May 12, 2016

Conversation

dellis1972
Copy link
Contributor

This commit adds basic support for the MSBuild Unit Tests. The goal
of these tests is to ensure that the build of an android applicaition
works consistently on all the supported platforms.

The basic layout of a Unit test is as follows

[Test]
public void BuildReleaseApplication ()
{
    var proj = new XamarinAndroidApplicationProject () {
        IsRelease = true,
    };
    using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
        Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
    }
}

It is a standard Unit test. First we create a XamarinAndroidApplicatonProject
and set its properties. You can use the proj to add new source files,
references, assets, resources and nuget packages. By default you will get
a standard "HelloWorld" android application.
Once you have the project you will need to create either a Apk or Dll builder
via the helper methods

CreateApkBuilder
CreateDllBuilder

CreateApkBuilder will create an apk and by default will execute the
SignAndroidPackage build target. the CreateDllBuilder will produce
a dll. The source files are created in a temp directory relative to
the build output of the unit tests. By default this is

src/Xamarin.Android.Build.Tasks/UnitTests/Xamarin.Android.Build.Tests/bin/$(Configuraiton)/temp

Once you have a builder you can then call Build passing in the project. There are
also methods available for Clean and Save. Running any of these will cause
the Unit test to shell out to xbuild/msbuild and attempt to build the project.
Test results are written to a build.log file.
If a unit test passes then the test directory is removed. If a test fails
the directory and the build.log will be left in place for investigation.

@dellis1972
Copy link
Contributor Author

@jonpryor don't merge this yet (if you are tempted) I still need to update it to use the xabuild script rather than system xbuild. Also it needs updating to look for the built framework.

@dellis1972 dellis1972 force-pushed the msbuildtests branch 2 times, most recently from 23a2d79 to 1a267e2 Compare May 9, 2016 15:35
@jonpryor
Copy link
Member

jonpryor commented May 9, 2016

+++ src/Xamarin.Android.Build.Tasks/UnitTests/Xamarin.Android.Build.Tests/BuildTest.cs

Convention is that unit tests go into a nested Test directory, or Tests (oops), not UnitTests, i.e. this should be src/Xamarin.Android.Build.Tasks/Test/Xamarin.Android.Build.Tests/BuildTest.cs.

@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\..\Configuration.props" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this file is indented with tabs while the other .csproj files are indented with spaces, two spaces per indent, e.g. Mono.Android.csproj.

Should it be fixed for consistency?

@jonpryor
Copy link
Member

jonpryor commented May 9, 2016

This also needs a way to run the unit tests, e.g. a make run-all-tests target, a'la Java.Interop.

@dellis1972 dellis1972 force-pushed the msbuildtests branch 2 times, most recently from ff3c939 to 7550a85 Compare May 11, 2016 11:13
@dellis1972
Copy link
Contributor Author

@jonpryor I've updated this to move the UnitTests to Tests and added a runner.

-output=bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt ;
endef

run-tests: $(TESTS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be run-nunit-tests, to differentiate from the run-apk-tests in PR #32.

@@ -1,6 +1,12 @@
V ?= 0
CONFIGURATION = Debug
MSBUILD = xbuild /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS)
RUNTIME := $(shell if [ -f `which mono64` ] ; then echo mono64 ; else echo mono; fi) --debug=casts

TESTS = \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry; this should likewise be NUNIT_TESTS.

… MSBuild Tasks

This commit adds basic support for the MSBuild Unit Tests. The goal
of these tests is to ensure that the build of an android applicaition
works consistently on all the supported platforms.

The basic layout of a Unit test is as follows

	[Test]
	public void BuildReleaseApplication ()
	{
		var proj = new XamarinAndroidApplicationProject () {
			IsRelease = true,
		};
		using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
			Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
		}
	}

It is a standard Unit test. First we create a XamarinAndroidApplicatonProject
and set its properties. You can use the proj to add new source files,
references, assets, resources and nuget packages. By default you will get
a standard "HelloWorld" android application.
Once you have the project you will need to create either a Apk or Dll builder
via the helper methods

	CreateApkBuilder
	CreateDllBuilder

CreateApkBuilder will create an apk and by default will execute the
`SignAndroidPackage` build target. the CreateDllBuilder will produce
a dll. The source files are created in a temp directory relative to
the build output of the unit tests. By default this is

	src/Xamarin.Android.Build.Tasks/UnitTests/Xamarin.Android.Build.Tests/bin/$(Configuraiton)/temp

Once you have a builder you can then call Build passing in the project. There are
also methods available for Clean and Save. Running any of these will cause
the Unit test to shell out to xbuild/msbuild and attempt to build the project.
Test results are written to a build.log file.
If a unit test passes then the test directory is removed. If a test fails
the directory and the build.log will be left in place for investigation.
@jonpryor jonpryor merged commit 7634c6d into dotnet:master May 12, 2016
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Apr 26, 2021
(Commercial) Xamarin.Android v11.3 is being tracked in the
[xamarin-android/d16-10][0] branch, which was branched from
commit eac74eb.

Bump `$(ProductVersion)` to 11.3.99 to track development progress of
the *next* version of Xamarin.Android.

Additionally, bump various submodules to their "main" equivalents
to mirror the d16-10 branch commit 496a43a, and update `.gitmodules`
so that the correct branch name is used:

Changes: mono/debugger-libs@8bf09ce...08268b7

  * mono/debugger-libs@08268b7: Add Module.ApplyChanges (dotnet#342)
  * mono/debugger-libs@1b5a55a: Fix assembly version after converting projects to SDK style

Changes: mono/opentk@933939d...50128f7

  * mono/opentk@50128f7a: Create Xamarin.Legacy.OpenTK Nuget Package (dotnet#28)
  * mono/opentk@72f4b085: Merge pull request dotnet#26 from dellis1972/ci
  * mono/opentk@b8fd3d2f: Fix Path issue
  * mono/opentk@62fd3b17: Clean up
  * mono/opentk@3a1a53c7: Add missing files. Update .gitignore
  * mono/opentk@e657cf71: Build with dotnet
  * mono/opentk@6e9a6160: Switch to using Xamarin.Legacy.Sdk
  * mono/opentk@a46a0668: rework
  * mono/opentk@cdae43e0: Initial Commit for Building Android

Changes: dotnet/android-tools@d92fc3e...c5732a0

  * dotnet/android-tools@c5732a0: [Xamarin.Android.Tools.AndroidSdk] Support Microsoft Dist JDK (dotnet#117)
  * dotnet/android-tools@52ef989: [Xamarin.Android.Tools.AndroidSdk] Fix CS0168 warning (dotnet#116)

[0]: https://github.com/xamarin/xamarin-android/commits/d16-10
jonpryor added a commit that referenced this pull request Apr 27, 2021
(Commercial) Xamarin.Android v11.3 is being tracked in the
[xamarin-android/d16-10][0] branch, which was branched from
commit eac74eb.

Bump `$(ProductVersion)` to 11.3.99 to track development progress of
the *next* version of Xamarin.Android.

Additionally, bump various submodules to their "main" equivalents
to mirror the d16-10 branch commit 496a43a, and update `.gitmodules`
so that the correct branch name is used:

Changes: mono/debugger-libs@8bf09ce...08268b7

  * mono/debugger-libs@08268b7: Add Module.ApplyChanges (#342)
  * mono/debugger-libs@1b5a55a: Fix assembly version after converting projects to SDK style

Changes: mono/opentk@933939d...50128f7

  * mono/opentk@50128f7a: Create Xamarin.Legacy.OpenTK Nuget Package (#28)
  * mono/opentk@72f4b085: Merge pull request #26 from dellis1972/ci
  * mono/opentk@b8fd3d2f: Fix Path issue
  * mono/opentk@62fd3b17: Clean up
  * mono/opentk@3a1a53c7: Add missing files. Update .gitignore
  * mono/opentk@e657cf71: Build with dotnet
  * mono/opentk@6e9a6160: Switch to using Xamarin.Legacy.Sdk
  * mono/opentk@a46a0668: rework
  * mono/opentk@cdae43e0: Initial Commit for Building Android

Changes: dotnet/android-tools@d92fc3e...c5732a0

  * dotnet/android-tools@c5732a0: [Xamarin.Android.Tools.AndroidSdk] Support Microsoft Dist JDK (#117)
  * dotnet/android-tools@52ef989: [Xamarin.Android.Tools.AndroidSdk] Fix CS0168 warning (#116)

[0]: https://github.com/xamarin/xamarin-android/commits/d16-10
jonathanpeppers pushed a commit that referenced this pull request Apr 27, 2021
(Commercial) Xamarin.Android v11.3 is being tracked in the
[xamarin-android/d16-10][0] branch, which was branched from
commit eac74eb.

Bump `$(ProductVersion)` to 11.3.99 to track development progress of
the *next* version of Xamarin.Android.

Additionally, bump various submodules to their "main" equivalents
to mirror the d16-10 branch commit 496a43a, and update `.gitmodules`
so that the correct branch name is used:

Changes: mono/debugger-libs@8bf09ce...08268b7

  * mono/debugger-libs@08268b7: Add Module.ApplyChanges (#342)
  * mono/debugger-libs@1b5a55a: Fix assembly version after converting projects to SDK style

Changes: mono/opentk@933939d...50128f7

  * mono/opentk@50128f7a: Create Xamarin.Legacy.OpenTK Nuget Package (#28)
  * mono/opentk@72f4b085: Merge pull request #26 from dellis1972/ci
  * mono/opentk@b8fd3d2f: Fix Path issue
  * mono/opentk@62fd3b17: Clean up
  * mono/opentk@3a1a53c7: Add missing files. Update .gitignore
  * mono/opentk@e657cf71: Build with dotnet
  * mono/opentk@6e9a6160: Switch to using Xamarin.Legacy.Sdk
  * mono/opentk@a46a0668: rework
  * mono/opentk@cdae43e0: Initial Commit for Building Android

Changes: dotnet/android-tools@d92fc3e...c5732a0

  * dotnet/android-tools@c5732a0: [Xamarin.Android.Tools.AndroidSdk] Support Microsoft Dist JDK (#117)
  * dotnet/android-tools@52ef989: [Xamarin.Android.Tools.AndroidSdk] Fix CS0168 warning (#116)

[0]: https://github.com/xamarin/xamarin-android/commits/d16-10
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants