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

UnitTests failure with Realm Xamarin #1431

Closed
teryngull opened this issue Jun 5, 2017 · 3 comments
Closed

UnitTests failure with Realm Xamarin #1431

teryngull opened this issue Jun 5, 2017 · 3 comments
Assignees
Labels

Comments

@teryngull
Copy link

We have a separate solution that houses our POCO's for use in our Xamarin.Forms mobile app. We have added Realm to one of the POCO's. The solution also has a Unit Test project. We have one unit test, that doesn't have anything to do with the POCO that we added Realm to, but we are getting a failure. This solution does not contain our droid and ios projects, so I'm not sure how to resolve.

Test method MyApp.Common.UnitTests.Utilities.UtilitiesTest.GetStateAbbreviationTest threw exception:

System.TypeInitializationException: The type initializer for '' threw an exception. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
at Realms.Schema.RealmSchema.AddDefaultTypes(IEnumerable`1 types)
at RealmModuleInitializer.Initialize()
at .cctor()
--- End of inner exception stack trace ---
at MyApp.Common.UnitTests.Utilities.UtilitiesTest.GetStateAbbreviationTest()

We've tried adding Realm to the UnitTests project as well, but it didn't change and still failed the test. The test is below:

[TestClass]
	public class UtilitiesTest
	{
		[TestMethod]
		public void GetStateAbbreviationTest()
		{
			var abbreviation = new Common.Utilities.Utilities().GetStateAbbreviation("SOUTH CAROLINA");

			Assert.AreEqual(abbreviation, "SC");
		}
	}

The method the test is executing looks like this (removing most states for brevity):

public string GetStateAbbreviation(string stateName)
	{
		Dictionary<string, string> stateList = new Dictionary<string, string>();
		stateList.Add("ALABAMA", "AL");
		stateList.Add("SOUTH CAROLINA", "SC");
		stateList.Add("WYOMING", "WY");
		if (!string.IsNullOrEmpty(stateName) && stateList.ContainsKey(stateName.ToUpper()))
			return stateList[stateName.ToUpper()];

		return null;
	}

Why does this test fail with a Realm error if we aren't trying to test something for Realm? And is there any solution?

  • Realm Version: v1.4.0
@nirinchev
Copy link
Member

That's a bug on our part - our weaver creates a .cctor for your assembly to populate the initial schema which then invokes the PCL version of the method, which promptly throws. I'll try to get it fixed ASAP.

@teryngull
Copy link
Author

So, I just started using Realm and it doesn't look like you guys do pre-release builds that I could pull the update into my app? To get this fixed, am I supposed to compile your code?

@nirinchev
Copy link
Member

We're still investigating how to best deliver our nightly builds and we haven't prioritized it yet. For now, letting us know which commit/PR you're interested in is the only way to get a pre-release :)

Here's the one related to your issue. Keep in mind that accessing things from Realm is still unsupported in PCL unit test, but at least it shouldn't prevent you from testing your other code.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants