简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM