unit testing Xamarin Form Android project and getting theme attribute conflicts

Hi all,

Years ago I wrote a few android apps, and I've decided to get back in and try it with Xamarin. After going back and forth on ideas, I decided to give the xamarin forms a whirl. From the defaults I generated a forms app with the following:


Now from my understanding, I created an additional Xamarin.Forms.Droid.UITest project using XUnit (Note: I've tried the default of NUnit too)

I've got a mix of styles (from the PCL) and theme (from Droid).

Recently I asked a question over trying to get my theme recognized within the android test project: Unit testing a Xamarin Forms Android specific code project

I'm not running into a conflict that shows up within xunit / nunit as the testing strategy. I feel like it's because the FormsAppCompatActivity with an older activity type, but I'm new to Xamarin and am unsure on how to approach this.

I get a lot of these type of errors:

Attribute layout_anchorGravity already defined with incompatible format.

The full list of the similar Attribute errors is:

  • fabSize
  • tabMode
  • expandedTitleGravity
  • layout_scollFlags
  • layout_collapseMode
  • collapsedTitleGravity
  • tabGravity
  • showDividers
  • displayOptions
  • showAsActions
  • actionBarSize

here is the basic code... At this point, I got a simple test of forcing it to be false to know it works.

//Within the Android Forms project, I have this inheritance:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity {
    // typical code

//within the Android UITest project
public class MainActivity : Xunit.Runners.UI.RunnerActivity {
    // tests can be inside the main assembly

    // or in any reference assemblies           

    // or in any assembly that you load (since JIT is available)

#if false
    // you can use the default or set your own custom writer (e.g. save to web site and tweet it ;-)
    Writer = new TcpTextWriter ("", 16384);
    // start running the test suites as soon as the application is loaded
    AutoStart = true;
    // crash the application (to ensure it's ended) and return to springboard
    TerminateAfterExecution = true;
    // you cannot add more assemblies once calling base

Any help would be much appreciated,

P.S. I've also asked about this on stack overflow without resolution: https://stackoverflow.com/questions/45070750/xamarin-android-uitest-theme-style-conflicts


  • KellyVernonKellyVernon USMember

    I assuming this is the right approach, but I could be completely wrong. The main thing is that I'm trying to do is integration testing (really unit testing android code, but like we all know, we have to go through the emulator at times).

    Where this really started was that I had a basic UI that had a mix of styles and themes. The problem when going down this path was the unit testing project saying: hey buddy I can't find the theme that was referenced within the app. Eventually, with the help of an individual on Stack Overflow, that person had told me to change the reference to @style/mytheme. After doing this, the style and themes were seen from the project, but now I get the styling issues. I mentioned above.

    Do you others do unit testing or integration testing of your xamarin forms android app with AppCompat activities? How do you approach this? I've looked around, and it seems that most tutorials show this concept pre AppCompat.

Sign In or Register to comment.