Jakub Arnold
Jakub Arnold

Reputation: 87220

How can I use Xamarin.Forms in a NUnit Library project?

I wanted to test out some binding code using BindableObject in a NUnit Library project, but I keep getting the error

You MUST call Xamarin.Forms.Init(); prior to using it.

The problem is, that based on the source code in the assembly browser, that function is only defined in Xamarin.Froms.Platform.iOS, which I do not have in the NUnit project. How can I write simple unit tests with Xamarin.Forms? Should I use a different project template, or somehow customize the build?

Upvotes: 1

Views: 1240

Answers (1)

Stephane Delcroix
Stephane Delcroix

Reputation: 16232

As of Xamarin.Forms 1.2.3, you can't*. The BindableObject code and the Layouting code require a Platform to be set, and the API for doing so is internal.

This is known, and could be solved in the future, by allowing a MockPlatform to be set for tests, or something similar.

*: Well, you can, if your Nunit project is also a platform project, and run on the divide or the simulator, and not ran by the unit runner directly.

Upvotes: 5

Related Questions