Bug 6043 - Bind ActivityInstrumentationTestCase2
Summary: Bind ActivityInstrumentationTestCase2
Status: RESOLVED DUPLICATE of bug 2129
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: PC Mac OS
: Low enhancement
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2012-07-09 10:36 UTC by Jonathan Pryor
Modified: 2016-09-05 12:06 UTC (History)
6 users (show)

Tags: XATriaged
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jonathan Pryor 2012-07-09 10:36:00 UTC
ActivityInstrumentationTestCase2 isn't bound because the junit.framework package isn't bound, and ActivityInstrumentationTestCase2 (indirectly) has junit.framework.TestCase as a base class.

We should bind the junit.framework package so that most/all of the android.test package can be bound.
Comment 4 Atsushi Eno 2013-06-03 04:29:40 UTC
I haven't updated the status, while I had tried this a couple of times. Current situation is:

- junit.framework can be bound if we unlimit the API.
- But XA fails to initialize assembly loading when it is launched via instrumentation. (Yet I believe that other instrumentation-related limitations are now gone.)
- Moreover, JUnit test requires that there is an empty constructor, but there is no way to generate such a constructor for our Android Callable Wrapper classes. Hence it is impossible to make use of it.

Hence JUnit is (still) not usable for XA.
Comment 5 Jonathan Pryor 2013-06-03 06:39:11 UTC
Why does JUnit require an "empty constructor"? That seems like a rather odd requirement...
Comment 6 Atsushi Eno 2013-06-03 06:45:28 UTC
Ask JUnit people, not me :/
Comment 7 Jonathan Pryor 2013-06-03 18:03:45 UTC
A cursory search of teh internetz doesn't show any mention/requirement that JUnit tests have empty constructors. Default constructors, almost certainly, but "empty"? (That's not even possible anyway, as the compiler will insert a super() call, ensuring that the constructor will never be entirely empty...)

Attempting to ask on #android-dev/irc.freenode.net elicits no additional information; they've never heard of such a requirement.

Where did you read about such a requirement?
Comment 8 Atsushi Eno 2013-06-03 18:09:02 UTC
From the actual run.
Comment 10 Atsushi Eno 2013-06-17 10:40:00 UTC
We will plan to support equivalent feature in different manner.
Comment 11 Jonathan Peppers 2015-02-25 17:13:21 UTC
Is this still happening?

I tried to do this myself a while ago: http://stackoverflow.com/questions/20598130/testing-activities-in-xamarin-android/20707385#20707385

It would be a cool feature that would allow for better unit testing on Android.
Comment 12 Jonathan Pryor 2015-02-25 19:02:01 UTC
This is "still happening" -- junit.framework is still not bound, nor is ActivityInstrumentationTestCase2 bound.

Generating an empty constructor (Comment #4) *may* be possible now, as [Export] can be used on constructors, and it is possible to provide arguments within the `super()` constructor statement via ExportAttribute.SuperArgumentString:


There has also been work to support <instrumentation/>, so in theory most of the blocking issues in Comment #4 may actually be addressed/addressable now.

We'd have to try it.

In the meantime, we have Xamarin.Android.NUnitLite.dll, which allows use of NUnit unit tests and assertions, and it can be started for on-device "unit test" purposes via `adb shell am instrument`:

	// Add to your project:
	[Instrumentation (Name="my.TestInstrumentation")]
	public class TestInstrumentation : TestSuiteInstrumentation {

		public TestInstrumentation (IntPtr handle, JniHandleOwnership transfer)
			: base (handle, transfer)

		protected override void AddTests ()
			AddTest (Assembly.GetExecutingAssembly ());

Then you can launch the tests with:

> adb shell am instrument -w @PACKAGE_NAME@/my.TestInstrumentation
Comment 13 Atsushi Eno 2015-07-21 11:19:36 UTC
We still kind of want this to reduce possible removal of API (and extra build warnings).
Comment 15 Atsushi Eno 2016-09-05 12:06:15 UTC
It is not strictly a complete duplicate but it practically is.

*** This bug has been marked as a duplicate of bug 2129 ***